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. --- THANKS.md | 1 + core/events.lua | 9 ++++++++- core/ui.lua | 4 ++++ src/textadept.c | 4 +--- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/THANKS.md b/THANKS.md index d3ee3b00..d246b0ff 100644 --- a/THANKS.md +++ b/THANKS.md @@ -34,6 +34,7 @@ private contract work related to Textadept. * Carl Sturtivant * Chris Emerson * Daniel Wutke +* Gabriel Dubatti * Gilles Grégoire * Giovanni Salmeri * Ivan Baidakou 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'] diff --git a/src/textadept.c b/src/textadept.c index a9a044f3..1b5eb203 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -1846,9 +1846,7 @@ static void w_quit_osx(GtkosxApplication*_, void*__) { */ static void t_tabchange(GtkNotebook*_, GtkWidget*__, int page_num, void*___) { if (tab_sync) return; - lL_event(lua, "buffer_before_switch", -1); - lL_gotodoc(lua, focused_view, page_num + 1, FALSE); - lL_event(lua, "buffer_after_switch", -1); + lL_event(lua, "tab_clicked", LUA_TNUMBER, page_num + 1, -1); } /** -- cgit v1.2.3