From 891bee0e40f31907e11333dadf7adf4b897250ee Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Sun, 1 Mar 2009 18:16:38 -0500 Subject: Ignore null byte for specific Scintilla messages; use buffer:get_text() again. --- core/ext/find.lua | 2 +- core/ext/pm/ctags_browser.lua | 2 +- core/file_io.lua | 4 ++-- src/lua_interface.c | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/ext/find.lua b/core/ext/find.lua index 018eaefe..064a7ddb 100644 --- a/core/ext/find.lua +++ b/core/ext/find.lua @@ -70,7 +70,7 @@ function find.find(text, next, flags, nowrap, wrapped) elseif flags < 16 then -- lua pattern search (forward search only) text = text:gsub('\\[abfnrtv\\]', escapes) - local buffer_text = buffer:text_range(0, buffer.length) + local buffer_text = buffer:get_text(buffer.length) local results = { buffer_text:find(text, buffer.anchor + increment) } if #results > 0 then result = results[1] diff --git a/core/ext/pm/ctags_browser.lua b/core/ext/pm/ctags_browser.lua index a0d8aaa2..23556f68 100644 --- a/core/ext/pm/ctags_browser.lua +++ b/core/ext/pm/ctags_browser.lua @@ -211,7 +211,7 @@ function perform_action(selected_item) if item.children then item = item.children end end if item.pattern then - local buffer_text = buffer:text_range(0, buffer.length) + local buffer_text = buffer:get_text(buffer.length) local search_text = item.pattern:gsub('\\/', '/') local s = buffer_text:find(search_text, 1, true) if s then diff --git a/core/file_io.lua b/core/file_io.lua index 9ad6dffd..7649f1ed 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -169,7 +169,7 @@ function set_encoding(buffer, encoding) local iconv = textadept.iconv local pos = buffer.current_pos local first_visible_line = buffer.first_visible_line - local text = buffer:text_range(0, buffer.length) + local text = buffer:get_text(buffer.length) text = iconv(text, buffer.encoding, 'UTF-8') text = iconv(text, encoding, buffer.encoding) text = iconv(text, 'UTF-8', encoding) @@ -189,7 +189,7 @@ function save(buffer) textadept.check_focused_buffer(buffer) if not buffer.filename then return save_as(buffer) end textadept.events.handle('file_before_save', buffer.filename) - local text = buffer:text_range(0, buffer.length) + local text = buffer:get_text(buffer.length) if buffer.encoding then local bom = buffer.encoding_bom or '' text = bom..textadept.iconv(text, buffer.encoding, 'UTF-8') diff --git a/src/lua_interface.c b/src/lua_interface.c index 7c219720..3a7e5e38 100644 --- a/src/lua_interface.c +++ b/src/lua_interface.c @@ -1016,6 +1016,8 @@ static int l_call_scintilla(lua_State *lua, ScintillaObject *sci, int msg, if (p1_type == tLENGTH) params[0] = len; return_string = reinterpret_cast(malloc(sizeof(char) * len + 1)); return_string[len] = '\0'; + if (msg == SCI_GETTEXT || msg == SCI_GETSELTEXT || msg == SCI_GETCURLINE) + len--; // Scintilla appends '\0' for these messages; compensate params[1] = reinterpret_cast(return_string); } -- cgit v1.2.3