mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
suppress the misspelled marker only when typing in a word the first time
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37463 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
7a9e8f2ec6
commit
f361c26a05
@ -700,6 +700,7 @@ CursorStatus BufferView::cursorStatus(DocIterator const & dit) const
|
||||
|
||||
void BufferView::bookmarkEditPosition()
|
||||
{
|
||||
d->cursor_.markEditPosition();
|
||||
// Don't eat cpu time for each keystroke
|
||||
if (d->cursor_.paragraph().id() == d->bookmark_edit_position_)
|
||||
return;
|
||||
|
@ -503,6 +503,7 @@ Row const & Cursor::textRow() const
|
||||
void Cursor::resetAnchor()
|
||||
{
|
||||
anchor_ = *this;
|
||||
checkNewWordPosition();
|
||||
}
|
||||
|
||||
|
||||
@ -519,6 +520,54 @@ void Cursor::setCursorToAnchor()
|
||||
}
|
||||
|
||||
|
||||
void Cursor::markEditPosition()
|
||||
{
|
||||
if (inTexted() && new_word_.empty()) {
|
||||
FontSpan ow = locateWord(WHOLE_WORD);
|
||||
if (ow.size() == 1) {
|
||||
LYXERR(Debug::DEBUG, "start new word: "
|
||||
<< " par: " << pit()
|
||||
<< " pos: " << ow.first);
|
||||
new_word_ = *this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Cursor::clearNewWordPosition()
|
||||
{
|
||||
if (!new_word_.empty()) {
|
||||
LYXERR(Debug::DEBUG, "clear new word: "
|
||||
<< " par: " << pit()
|
||||
<< " pos: " << pos());
|
||||
new_word_.resize(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Cursor::checkNewWordPosition()
|
||||
{
|
||||
if (new_word_.empty())
|
||||
return ;
|
||||
if (!inTexted())
|
||||
clearNewWordPosition();
|
||||
else {
|
||||
if (paragraph().id() != new_word_.paragraph().id())
|
||||
clearNewWordPosition();
|
||||
else {
|
||||
FontSpan ow = new_word_.locateWord(WHOLE_WORD);
|
||||
FontSpan nw = locateWord(WHOLE_WORD);
|
||||
if (nw.intersect(ow).empty())
|
||||
clearNewWordPosition();
|
||||
else
|
||||
LYXERR(Debug::DEBUG, "new word: "
|
||||
<< " par: " << pit()
|
||||
<< " pos: " << nw.first << ".." << nw.last);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Cursor::posBackward()
|
||||
{
|
||||
if (pos() == 0)
|
||||
|
17
src/Cursor.h
17
src/Cursor.h
@ -292,6 +292,15 @@ public:
|
||||
///
|
||||
void checkBufferStructure();
|
||||
|
||||
/// hook for text input to maintain the "new born word"
|
||||
void markEditPosition();
|
||||
|
||||
/// The position of the new born word
|
||||
/// As the user is entering a word without leaving it
|
||||
/// the result is not empty. When not in text mode
|
||||
/// and after leaving the word the result is empty.
|
||||
DocIterator newWord() const { return new_word_; }
|
||||
|
||||
public:
|
||||
//private:
|
||||
|
||||
@ -300,11 +309,19 @@ public:
|
||||
///
|
||||
void saveBeforeDispatchPosXY();
|
||||
|
||||
private:
|
||||
/// validate the "new born word" position
|
||||
void checkNewWordPosition();
|
||||
/// clear the "new born word" position
|
||||
void clearNewWordPosition();
|
||||
|
||||
private:
|
||||
///
|
||||
BufferView * bv_;
|
||||
/// the anchor position
|
||||
DocIterator anchor_;
|
||||
/// the start of the new born word
|
||||
DocIterator new_word_;
|
||||
///
|
||||
mutable DispatchResult disp_;
|
||||
/**
|
||||
|
@ -192,6 +192,16 @@ Paragraph & DocIterator::innerParagraph() const
|
||||
}
|
||||
|
||||
|
||||
FontSpan DocIterator::locateWord(word_location const loc) const
|
||||
{
|
||||
FontSpan f = FontSpan();
|
||||
|
||||
f.first = pos();
|
||||
top().paragraph().locateWord(f.first, f.last, loc);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
CursorSlice const & DocIterator::innerTextSlice() const
|
||||
{
|
||||
LASSERT(!empty(), /**/);
|
||||
|
@ -25,6 +25,7 @@ class MathAtom;
|
||||
class Paragraph;
|
||||
class Text;
|
||||
class InsetIterator;
|
||||
class FontSpan;
|
||||
|
||||
DocIterator doc_iterator_begin(Buffer const * buf, Inset const * inset = 0);
|
||||
DocIterator doc_iterator_end(Buffer const * buf, Inset const * inset = 0);
|
||||
@ -161,6 +162,9 @@ public:
|
||||
Paragraph & innerParagraph() const;
|
||||
/// return the inner text slice.
|
||||
CursorSlice const & innerTextSlice() const;
|
||||
/// the first and last positions of a word at top cursor slice
|
||||
/// \warning only works within text!
|
||||
FontSpan locateWord(word_location const loc) const;
|
||||
///
|
||||
Text * text() const;
|
||||
/// the containing inset or the cell, respectively
|
||||
|
@ -77,12 +77,34 @@ public:
|
||||
{
|
||||
return first == s.first && last == s.last;
|
||||
}
|
||||
|
||||
|
||||
inline bool inside(pos_type p) const
|
||||
{
|
||||
return first <= p && p <= last;
|
||||
}
|
||||
|
||||
inline size_t size() const
|
||||
{
|
||||
return empty() ? 0 : last - first;
|
||||
}
|
||||
|
||||
|
||||
inline FontSpan intersect(FontSpan const & f) const
|
||||
{
|
||||
FontSpan result = FontSpan();
|
||||
if (inside(f.first))
|
||||
result.first = f.first;
|
||||
else if (f.inside(first))
|
||||
result.first = first;
|
||||
else
|
||||
return result;
|
||||
if (inside(f.last))
|
||||
result.last = f.last;
|
||||
else if (f.inside(last))
|
||||
result.last = last;
|
||||
return result;
|
||||
}
|
||||
|
||||
inline bool empty() const
|
||||
{
|
||||
return first > last;
|
||||
|
@ -415,17 +415,17 @@ void RowPainter::paintFromPos(pos_type & vpos, bool changed)
|
||||
// don't draw misspelled marker for words at cursor position
|
||||
// we don't want to disturb the process of text editing
|
||||
BufferView const * bv = pi_.base.bv;
|
||||
Cursor const & cur = bv->cursor();
|
||||
bool current_word = false;
|
||||
if (cur.inTexted() && par_.id() == cur.paragraph().id()) {
|
||||
pos_type cpos = cur.pos();
|
||||
DocIterator const nw = bv->cursor().newWord();
|
||||
bool new_word = false;
|
||||
if (!nw.empty() && par_.id() == nw.paragraph().id()) {
|
||||
pos_type cpos = nw.pos();
|
||||
if (cpos > 0 && cpos == par_.size() && !par_.isWordSeparator(cpos-1))
|
||||
--cpos;
|
||||
else if (cpos > 0 && par_.isWordSeparator(cpos))
|
||||
--cpos;
|
||||
current_word = par_.isSameSpellRange(pos, cpos) ;
|
||||
new_word = par_.isSameSpellRange(pos, cpos) ;
|
||||
}
|
||||
if (!current_word)
|
||||
if (!new_word)
|
||||
paintMisspelledMark(orig_x, changed);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user