diff options
author | 2016-07-24 15:40:55 -0400 | |
---|---|---|
committer | 2016-07-24 15:40:55 -0400 | |
commit | e9474c8c82745d82ffb39ff1618a96b10f724077 (patch) | |
tree | c4955dbf53e73e050b132da79a9ecd5b3aa55530 /core | |
parent | 74049a11517ffb608bf64aabcc96535d1bc7b298 (diff) | |
download | textadept-e9474c8c82745d82ffb39ff1618a96b10f724077.tar.gz textadept-e9474c8c82745d82ffb39ff1618a96b10f724077.zip |
Added `events.TAB_CLICKED` event.
This allows for the user to override the default switch behavior (e.g. switch to
an existing split view that already has the target buffer open).
Thanks to Gabriel Dubatti.
Diffstat (limited to 'core')
-rw-r--r-- | core/events.lua | 9 | ||||
-rw-r--r-- | core/ui.lua | 4 |
2 files changed, 12 insertions, 1 deletions
diff --git a/core/events.lua b/core/events.lua index 849c4302..dcaf5716 100644 --- a/core/events.lua +++ b/core/events.lua @@ -218,6 +218,13 @@ local M = {} -- Emitted when suspending Textadept. If any handler returns `true`, Textadept -- does not suspend. -- This event is only emitted by the terminal version. +-- @field TAB_CLICKED (string) +-- Emitted when the user clicks on a buffer tab. +-- When connecting to this event, connect with an index of 1 if the handler +-- needs to run before Textadept switches between buffers. +-- Arguments: +-- +-- * _`index`_: The numeric index of the clicked tab. -- @field UPDATE_UI (string) -- Emitted after the view is visually updated. -- Arguments: @@ -366,7 +373,7 @@ local textadept_events = { 'buffer_deleted', 'buffer_new', 'csi', 'error', 'find', 'focus', 'initialized', 'keypress', 'menu_clicked', 'mouse', 'quit', 'replace', 'replace_all', 'reset_after', 'reset_before', 'resume', 'suspend', - 'view_after_switch', 'view_before_switch', 'view_new' + 'tab_clicked', 'view_after_switch', 'view_before_switch', 'view_new' } for _, e in pairs(textadept_events) do M[e:upper()] = e end diff --git a/core/ui.lua b/core/ui.lua index a30b5e7a..06d68776 100644 --- a/core/ui.lua +++ b/core/ui.lua @@ -302,6 +302,10 @@ events_connect(events.BUFFER_NEW, function() buffer:private_lexer_call(SETLEXERLANGUAGE, 'text') end) +-- Switches between buffers when a tab is clicked. +events_connect(events.TAB_CLICKED, + function(index) view:goto_buffer(_BUFFERS[index]) end) + -- Sets the title of the Textadept window to the buffer's filename. local function set_title() local filename = buffer.filename or buffer._type or _L['Untitled'] |