commit 786a6edb5487370b15724cc4446afbf22fc34831 Author: Jean-Marc Lasgouttes <lasgout...@lyx.org> Date: Sat Oct 8 12:12:19 2022 +0200
Disable completion when document is read-only. Being able to insert completion in a read-only document is definitely a bad idea. This patch acts both on indication of completion and on insertion itself. Fixes bug #12582. --- src/Text.cpp | 5 ++++- src/mathed/InsetMathMacro.cpp | 9 +++++++++ src/mathed/InsetMathNest.cpp | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Text.cpp b/src/Text.cpp index e4d532b..0ca32a4 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -2381,7 +2381,8 @@ void Text::setMacrocontextPosition(DocIterator const & pos) bool Text::completionSupported(Cursor const & cur) const { Paragraph const & par = cur.paragraph(); - return !cur.selection() + return !cur.buffer()->isReadonly() + && !cur.selection() && cur.pos() > 0 && (cur.pos() >= par.size() || par.isWordSeparator(cur.pos())) && !par.isWordSeparator(cur.pos() - 1); @@ -2398,6 +2399,8 @@ CompletionList const * Text::createCompletionList(Cursor const & cur) const bool Text::insertCompletion(Cursor & cur, docstring const & s) { LBUFERR(cur.bv().cursor() == cur); + if (cur.buffer()->isReadonly()) + return false; cur.recordUndo(); cur.insert(s); cur.bv().cursor() = cur; diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp index b4f64b4..3f4da74 100644 --- a/src/mathed/InsetMathMacro.cpp +++ b/src/mathed/InsetMathMacro.cpp @@ -1312,6 +1312,9 @@ void InsetMathMacro::infoize2(odocstream & os) const bool InsetMathMacro::completionSupported(Cursor const & cur) const { + if (cur.buffer()->isReadonly()) + return false; + if (displayMode() != DISPLAY_UNFOLDED) return InsetMathNest::completionSupported(cur); @@ -1322,6 +1325,9 @@ bool InsetMathMacro::completionSupported(Cursor const & cur) const bool InsetMathMacro::inlineCompletionSupported(Cursor const & cur) const { + if (cur.buffer()->isReadonly()) + return false; + if (displayMode() != DISPLAY_UNFOLDED) return InsetMathNest::inlineCompletionSupported(cur); @@ -1372,6 +1378,9 @@ docstring InsetMathMacro::completionPrefix(Cursor const & cur) const bool InsetMathMacro::insertCompletion(Cursor & cur, docstring const & s, bool finished) { + if (cur.buffer()->isReadonly()) + return false; + if (displayMode() != DISPLAY_UNFOLDED) return InsetMathNest::insertCompletion(cur, s, finished); diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 1d61679..54d96d9 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -2088,7 +2088,7 @@ docstring InsetMathNest::completionPrefix(Cursor const & cur) const bool InsetMathNest::insertCompletion(Cursor & cur, docstring const & s, bool finished) { - if (!cur.inMacroMode()) + if (cur.buffer()->isReadonly() || !cur.inMacroMode()) return false; // Contrary to Text, the whole inset should be recorded (#12581). -- lyx-cvs mailing list lyx-cvs@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-cvs