From e9474c8c82745d82ffb39ff1618a96b10f724077 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Sun, 24 Jul 2016 15:40:55 -0400 Subject: 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. --- core/events.lua | 9 ++++++++- core/ui.lua | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'core') 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'] -- cgit v1.2.3