* src/CutAndPaste.C (setSelectionRange, replaceWord): remove.
(replaceSelectionWithString): select the new string after
replacement; add a bool parameter indicating in which sense the
selection is made.
* src/lyxfind.C (replace): adapt to above changes.
(find): comment out debug message.
* src/frontends/controllers/ControlSpellchecker.C (isLetter):
rename parameter.
(nextWord): take a LCursor as parameter; set the selection over
the word that has been found.
(check): adapt to changes above (the length of the word is not
necessarily the length of the selection -- fixes bug 2068).
(replace): use cap::replaceSelectionWithString
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14708
a592a061-630c-0410-9148-
cb99ea01b6c8
}
-void setSelectionRange(LCursor & cur, pos_type length)
-{
- LyXText * text = cur.text();
- BOOST_ASSERT(text);
- if (!length)
- return;
- cur.resetAnchor();
- while (length--)
- text->cursorRight(cur);
- cur.setSelection();
-}
-
-
// simple replacing. The font of the first selected character is used
-void replaceSelectionWithString(LCursor & cur, string const & str)
+void replaceSelectionWithString(LCursor & cur, string const & str, bool backwards)
{
- LyXText * text = cur.text();
- BOOST_ASSERT(text);
recordUndo(cur);
+ DocIterator selbeg = cur.selectionBegin();
// Get font setting before we cut
- pos_type pos = cur.selEnd().pos();
- Paragraph & par = text->getPar(cur.selEnd().pit());
LyXFont const font =
- par.getFontSettings(cur.buffer().params(), cur.selBegin().pos());
+ selbeg.paragraph().getFontSettings(cur.buffer().params(), selbeg.pos());
// Insert the new string
+ pos_type pos = cur.selEnd().pos();
+ Paragraph & par = cur.selEnd().paragraph();
string::const_iterator cit = str.begin();
string::const_iterator end = str.end();
for (; cit != end; ++cit, ++pos)
// Cut the selection
cutSelection(cur, true, false);
+
+ // select the replacement
+ if (backwards) {
+ selbeg.pos() += str.length();
+ cur.setSelection(selbeg, -str.length());
+ } else
+ cur.setSelection(selbeg, str.length());
}
}
-// only used by the spellchecker
-void replaceWord(LCursor & cur, string const & replacestring)
-{
- LyXText * text = cur.text();
- BOOST_ASSERT(text);
-
- replaceSelectionWithString(cur, replacestring);
- setSelectionRange(cur, replacestring.length());
-
- // Go back so that replacement string is also spellchecked
- for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
- text->cursorLeft(cur);
-}
-
-
void eraseSelection(LCursor & cur)
{
//lyxerr << "LCursor::eraseSelection begin: " << cur << endl;
///
void cutSelection(LCursor & cur, bool doclear, bool realcut);
-/**
- * Sets the selection from the current cursor position to length
- * characters to the right. No safety checks.
+/* Replace using the font of the first selected character and select
+ * the new string. When \c backwards == false, set anchor before
+ * cursor; otherwise set cursor before anchor.
*/
-void setSelectionRange(LCursor & cur, lyx::pos_type length);
-/// simply replace using the font of the first selected character
-void replaceSelectionWithString(LCursor & cur, std::string const & str);
+void replaceSelectionWithString(LCursor & cur, std::string const & str,
+ bool backwards);
/// replace selection helper
void replaceSelection(LCursor & cur);
lyx::textclass_type c2,
InsetText & in, ErrorList &);
-// only used by the spellchecker
-void replaceWord(LCursor & cur, std::string const & replacestring);
-
///
std::string grabSelection(LCursor const & cur);
///
namespace {
-bool isLetter(DocIterator const & cur)
+bool isLetter(DocIterator const & dit)
{
- return cur.inTexted()
- && cur.inset().allowSpellCheck()
- && cur.pos() != cur.lastpos()
- && (cur.paragraph().isLetter(cur.pos())
+ return dit.inTexted()
+ && dit.inset().allowSpellCheck()
+ && dit.pos() != dit.lastpos()
+ && (dit.paragraph().isLetter(dit.pos())
// We want to pass the ' and escape chars to ispell
|| contains(lyxrc.isp_esc_chars + '\'',
- cur.paragraph().getChar(cur.pos())))
- && !isDeletedText(cur.paragraph(), cur.pos());
+ dit.paragraph().getChar(dit.pos())))
+ && !isDeletedText(dit.paragraph(), dit.pos());
}
-WordLangTuple nextWord(DocIterator & cur, ptrdiff_t & progress,
- BufferParams & bp)
+WordLangTuple nextWord(LCursor & cur, ptrdiff_t & progress)
{
+ BufferParams const & bp = cur.bv().buffer()->params();
bool inword = false;
bool ignoreword = false;
+ cur.resetAnchor();
string word, lang_code;
while (cur.depth()) {
if (!inword) {
inword = true;
ignoreword = false;
+ cur.resetAnchor();
word.clear();
lang_code = cur.paragraph().getFontSettings(bp, cur.pos()).language()->code();
}
}
} else { // !isLetter(cur)
if (inword)
- if (!word.empty() && !ignoreword)
+ if (!word.empty() && !ignoreword) {
+ cur.setSelection();
return WordLangTuple(word, lang_code);
- else
+ } else
inword = false;
}
SpellBase::Result res = SpellBase::OK;
- DocIterator cur = kernel().bufferview()->cursor();
+ LCursor cur = kernel().bufferview()->cursor();
while (cur && cur.pos() && isLetter(cur)) {
cur.backwardPos();
}
for (total = start; it; it.forwardPos())
++total;
- BufferParams & bufferparams = kernel().buffer().params();
exitEarly_ = false;
while (res == SpellBase::OK || res == SpellBase::IGNORED_WORD) {
- word_ = nextWord(cur, start, bufferparams);
+ word_ = nextWord(cur, start);
// end of document
if (getWord().empty()) {
lyxerr[Debug::GUI] << "Found word \"" << getWord() << "\"" << endl;
- int const size = getWord().size();
+ int const size = cur.selEnd().pos() - cur.selBegin().pos();
cur.pos() -= size;
kernel().bufferview()->putSelectionAt(cur, size, false);
// if we used a lfun like in find/replace, dispatch would do
lyxerr[Debug::GUI] << "ControlSpellchecker::replace("
<< replacement << ")" << std::endl;
BufferView & bufferview = *kernel().bufferview();
- cap::replaceWord(bufferview.cursor(), replacement);
+ cap::replaceSelectionWithString(bufferview.cursor(), replacement, true);
kernel().buffer().markDirty();
bufferview.update();
// fix up the count
return 0;
LCursor & cur = bv->cursor();
- lyx::cap::replaceSelectionWithString(cur, replacestr);
- lyx::cap::setSelectionRange(cur, replacestr.length());
- cur.top() = fw ? cur.selEnd() : cur.selBegin();
+ lyx::cap::replaceSelectionWithString(cur, replacestr, fw);
bv->buffer()->markDirty();
find(bv, searchstr, cs, mw, fw);
bv->update();
if (!bv || ev.action != LFUN_WORD_FIND)
return;
- lyxerr << "find called, cmd: " << ev << std::endl;
+ //lyxerr << "find called, cmd: " << ev << std::endl;
// data is of the form
// "<search>