aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2020-08-22 16:34:47 -0400
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2020-08-22 16:34:47 -0400
commit2835799ac0581f667c9ef9b66fe2b155a5348ae5 (patch)
tree7405670a30895c5a81c64c315fbe5040b7d4e147
parentd9ae118774a156b5d8ed2f1f2747c65bca0ce76a (diff)
Added `ui.command_entry.active` and fixed bugs in `events.KEYPRESS` handlers.
-rw-r--r--doc/manual.md3
-rw-r--r--modules/textadept/command_entry.lua3
-rw-r--r--modules/textadept/editing.lua40
-rw-r--r--modules/textadept/run.lua6
-rw-r--r--test/test.lua2
5 files changed, 33 insertions, 21 deletions
diff --git a/doc/manual.md b/doc/manual.md
index a48bb461..a0fb9181 100644
--- a/doc/manual.md
+++ b/doc/manual.md
@@ -1854,6 +1854,8 @@ N/A |Added |[highlight_all_matches][]
\_paths |Renamed |[paths][]
**ui** | |
bufstatusbar\_text |Renamed |[buffer_statusbar_text][]
+**ui.command_entry** | |
+N/A |Added |[active][]
**ui.dialogs** | |
N/A |Added |[progressbar()][]
**ui.find** | |
@@ -1895,6 +1897,7 @@ section below.
[select()]: api.html#textadept.snippets.select
[paths]: api.html#textadept.snippets.paths
[buffer_statusbar_text]: api.html#ui.buffer_statusbar_text
+[active]: api.html#ui.command_entry.active
[progressbar()]: api.html#ui.dialogs.progressbar
#### Buffer Indexing Changes
diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua
index db26b8f2..8033b48c 100644
--- a/modules/textadept/command_entry.lua
+++ b/modules/textadept/command_entry.lua
@@ -10,6 +10,8 @@ local M = ui.command_entry
-- running Lua code and filtering text through shell commands) and history.
-- @field height (number)
-- The height in pixels of the command entry.
+-- @field active (boolean)
+-- Whether or not the command entry is active.
module('ui.command_entry')]]
-- Command history per mode.
@@ -237,6 +239,7 @@ end
local orig_focus = M.focus
M.focus = function()
keys.mode = prev_key_mode
+ M.active = not M.active
orig_focus()
end
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index 39e54dac..1830e047 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -148,17 +148,19 @@ end)
-- Removes matched chars on backspace, taking multiple selections into account.
events.connect(events.KEYPRESS, function(code)
- if not M.auto_pairs or keys.KEYSYMS[code] ~= '\b' then return end
- buffer:begin_undo_action()
- for i = 1, buffer.selections do
- local pos = buffer.selection_n_caret[i]
- local complement = M.auto_pairs[buffer.char_at[pos - 1]]
- if complement and buffer.char_at[pos] == string.byte(complement) then
- buffer:set_target_range(pos, pos + 1)
- buffer:replace_target('')
+ if M.auto_pairs and keys.KEYSYMS[code] == '\b' and
+ not ui.command_entry.active then
+ buffer:begin_undo_action()
+ for i = 1, buffer.selections do
+ local pos = buffer.selection_n_caret[i]
+ local complement = M.auto_pairs[buffer.char_at[pos - 1]]
+ if complement and buffer.char_at[pos] == string.byte(complement) then
+ buffer:set_target_range(pos, pos + 1)
+ buffer:replace_target('')
+ end
end
+ buffer:end_undo_action()
end
- buffer:end_undo_action()
end, 1) -- need index of 1 because default key handler halts propagation
-- Highlights matching braces.
@@ -214,16 +216,18 @@ end)
-- Moves over typeover characters when typed, taking multiple selections into
-- account.
events.connect(events.KEYPRESS, function(code)
- if not M.typeover_chars or not M.typeover_chars[code] then return end
- local handled = false
- for i = 1, buffer.selections do
- local s, e = buffer.selection_n_start[i], buffer.selection_n_end[i]
- if s == e and buffer.char_at[s] == code then
- buffer.selection_n_start[i], buffer.selection_n_end[i] = s + 1, s + 1
- handled = true
+ if M.typeover_chars and M.typeover_chars[code] and
+ not ui.command_entry.active then
+ local handled = false
+ for i = 1, buffer.selections do
+ local s, e = buffer.selection_n_start[i], buffer.selection_n_end[i]
+ if s == e and buffer.char_at[s] == code then
+ buffer.selection_n_start[i], buffer.selection_n_end[i] = s + 1, s + 1
+ handled = true
+ end
end
+ if handled then return true end -- prevent typing
end
- if handled then return true end -- prevent typing
end)
-- Auto-indent on return.
@@ -474,7 +478,7 @@ end
-- Enclose selected text in punctuation or auto-paired characters.
events.connect(events.KEYPRESS, function(code, shift, ctrl, alt, cmd)
if M.auto_enclose and not buffer.selection_empty and code < 256 and
- not ctrl and not alt and not cmd then
+ not ctrl and not alt and not cmd and not ui.command_entry.active then
local char = string.char(code)
if char:find('^%P') then return end -- not punctuation
M.enclose(char, M.auto_pairs[code] or char)
diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua
index d76ae030..ffccc7e7 100644
--- a/modules/textadept/run.lua
+++ b/modules/textadept/run.lua
@@ -90,11 +90,11 @@ local function scan_for_error(message, ext_or_lexer)
end
detail.warning =
message:lower():find('warning') and not message:lower():find('error')
- -- Compile and run commands specify the file extension or lexer name used
- -- to determine the command, so the error patterns used are guaranteed to
+ -- Compile and run commands specify the file extension or lexer name used
+ -- to determine the command, so the error patterns used are guaranteed to
-- be correct. Build commands have no such context and instead iterate
-- through all possible error patterns. Only consider the error/warning
- -- valid if the extracted filename's extension or lexer name matches the
+ -- valid if the extracted filename's extension or lexer name matches the
-- error pattern's extension or lexer name.
if ext_or_lexer then return detail end
local ext = detail.filename:match('[^/\\.]+$')
diff --git a/test/test.lua b/test/test.lua
index db3c2b39..7e7894af 100644
--- a/test/test.lua
+++ b/test/test.lua
@@ -1161,6 +1161,7 @@ function test_command_entry_run()
['\t'] = function() tab_pressed = true end
}, nil, 2)
ui.update() -- redraw command entry
+ assert_equal(ui.command_entry.active, true)
assert_equal(ui.command_entry:get_lexer(), 'text')
assert(ui.command_entry.height > ui.command_entry:text_height(0), 'height < 2 lines')
ui.command_entry:set_text('foo')
@@ -1168,6 +1169,7 @@ function test_command_entry_run()
events.emit(events.KEYPRESS, not CURSES and 0xFF0D or 343) -- \n
assert_equal(command_run, 'foo')
assert(tab_pressed, '\\t not registered')
+ assert_equal(ui.command_entry.active, false)
assert_raises(function() ui.command_entry.run(function() end, 1) end, 'table/string/nil expected, got number')
assert_raises(function() ui.command_entry.run(function() end, {}, 1) end, 'string/nil expected, got number')