From b567ef36bb9dc61b884012669db48ac08c4c45a8 Mon Sep 17 00:00:00 2001 From: Richard Kimberly Heck Date: Wed, 21 Mar 2018 23:08:12 -0400 Subject: [PATCH] Fix bug #11084. Allow unicode-insert to accept a sequence of codepoints. (cherry picked from commits 83b1ac3b, f7d502d0, and a714f6cb) --- src/BufferView.cpp | 28 ++++++++++++++++++++++++++++ src/LyXAction.cpp | 6 +++--- src/Text3.cpp | 15 --------------- src/mathed/InsetMathNest.cpp | 16 ---------------- src/support/lstrings.h | 2 ++ status.23x | 2 ++ 6 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index b1c995d471..73cf4520b9 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -65,6 +65,7 @@ #include "insets/InsetText.h" #include "mathed/MathData.h" +#include "mathed/InsetMathNest.h" #include "frontends/alert.h" #include "frontends/Application.h" @@ -1891,6 +1892,33 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) } + case LFUN_UNICODE_INSERT: { + if (cmd.argument().empty()) + break; + + FuncCode code = cur.inset().currentMode() == Inset::MATH_MODE ? + LFUN_MATH_INSERT : LFUN_SELF_INSERT; + int i = 0; + while (true) { + docstring const arg = from_utf8(cmd.getArg(i)); + if (arg.empty()) + break; + if (!isHex(arg)) { + LYXERR0("Not a hexstring: " << arg); + ++i; + continue; + } + char_type c = hexToInt(arg); + if (c >= 32 && c < 0x10ffff) { + LYXERR(Debug::KEY, "Inserting c: " << c); + lyx::dispatch(FuncRequest(code, docstring(1, c))); + } + ++i; + } + break; + } + + // This would be in Buffer class if only Cursor did not // require a bufferview case LFUN_INSET_FORALL: { diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index d2e92b1c94..83625105ab 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -3841,10 +3841,10 @@ void LyXAction::init() /*! * \var lyx::FuncCode lyx::LFUN_UNICODE_INSERT * \li Action: Inserts a single unicode character. - * \li Syntax: unicode-insert - * \li Params: : The character to insert, given as its code + * \li Syntax: unicode-insert ... + * \li Params: : The character to insert, given as its code point, in hexadecimal. - * \li Sample: unicode-insert 0x0100 + * \li Sample: unicode-insert 0x0100 0x0259 * \li Origin: Lgb, 22 Oct 2006 * \endvar */ diff --git a/src/Text3.cpp b/src/Text3.cpp index adeb80b88f..e0358fc464 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -1695,21 +1695,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) bv->buffer().errors("Paste"); break; - case LFUN_UNICODE_INSERT: { - if (cmd.argument().empty()) - break; - docstring hexstring = cmd.argument(); - if (isHex(hexstring)) { - char_type c = hexToInt(hexstring); - if (c >= 32 && c < 0x10ffff) { - lyxerr << "Inserting c: " << c << endl; - docstring s = docstring(1, c); - lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s)); - } - } - break; - } - case LFUN_QUOTE_INSERT: { cap::replaceSelection(cur); cur.recordUndo(); diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index af50a7ec3c..afe4f062cd 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -1246,22 +1246,6 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) break; } - case LFUN_UNICODE_INSERT: { - if (cmd.argument().empty()) - break; - docstring hexstring = cmd.argument(); - if (isHex(hexstring)) { - char_type c = hexToInt(hexstring); - if (c >= 32 && c < 0x10ffff) { - docstring s = docstring(1, c); - FuncCode code = currentMode() == MATH_MODE ? - LFUN_MATH_INSERT : LFUN_SELF_INSERT; - lyx::dispatch(FuncRequest(code, s)); - } - } - break; - } - case LFUN_DIALOG_SHOW_NEW_INSET: { docstring const & name = cmd.argument(); string data; diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 398bf8dd33..9bcff42afa 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -326,6 +326,8 @@ docstring wrapParas(docstring const & str, int const indent = 0, /// If \p keepempty is true, empty strings will be pushed to the vector as well /// If \p trimit is true, leading and trailing whitespace will be trimmed from /// all values. Note that this can affect what counts as "empty". +/// NOTE: If you want to split a string on whitespace, then do: +/// getVectorFromString(str, " ", false, true); std::vector const getVectorFromString(std::string const & str, std::string const & delim = std::string(","), bool keepempty = false, bool trimit = true); diff --git a/status.23x b/status.23x index 5b75dfb9ab..94c311dbba 100644 --- a/status.23x +++ b/status.23x @@ -203,6 +203,8 @@ What's new - Allow for spaces in bibliography keys (bug 9847). +- Allow LFUN_UNICODE_INSERT to take multiple arguments (bug 11084). + * INTERNALS