// FIXME
if (arg.size() > 100 || arg.empty()) {
// Get word or selection
- bv_->getLyXText()->selectWordWhenUnderCursor(LyXText::WHOLE_WORD);
+ bv_->getLyXText()->selectWordWhenUnderCursor(lyx::WHOLE_WORD);
arg = bv_->getLyXText()->selectionAsString(buffer_, false);
// FIXME: where is getLyXText()->unselect(bv_) ?
}
+
+2003-07-01 André Pönitz <poenitz@gmx.net>
+
+ * text.C:
+ * text2.C:
+ * text3.C:
+ * text_funcs.[Ch]:
+ * textcursor.h:
+ * lyxtext.h: shuffle pure paragraph/cursor related cursor movement from
+ text*.C to text_func.C
+
2003-07-01 Lars Gullik Bjønnes <larsbj@gullik.net>
* introduce namespace lyx::support
REFRESH_AREA = 2
};
- ///
- enum word_location {
- // the word around the cursor, only if the cursor is
- //not at a boundary
- WHOLE_WORD_STRICT,
- // the word around the cursor
- WHOLE_WORD,
- /// the word begining from the cursor position
- PARTIAL_WORD,
- /// the word around the cursor or before the cursor
- PREVIOUS_WORD,
- /// the next word (not yet used)
- NEXT_WORD
- };
-
/// Constructor
LyXText(BufferView *);
/// sets inset as owner
void clearSelection();
/// select the word we need depending on word_location
- void getWord(LyXCursor & from, LyXCursor & to, word_location const);
+ void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const);
/// just selects the word the cursor is in
- void selectWord(word_location loc);
+ void selectWord(lyx::word_location loc);
/// returns the inset at cursor (if it exists), 0 otherwise
Inset * getInset() const;
///
void backspace();
///
- bool selectWordWhenUnderCursor(word_location);
+ bool selectWordWhenUnderCursor(lyx::word_location);
///
enum TextCase {
///
private:
///
mutable RowList rowlist_;
- ///
- void cursorLeftOneWord(LyXCursor &);
///
float getCursorX(RowList::iterator rit, lyx::pos_type pos,
#endif
+ ///
+ enum word_location {
+ // the word around the cursor, only if the cursor is
+ //not at a boundary
+ WHOLE_WORD_STRICT,
+ // the word around the cursor
+ WHOLE_WORD,
+ /// the word begining from the cursor position
+ PARTIAL_WORD,
+ /// the word around the cursor or before the cursor
+ PREVIOUS_WORD,
+ /// the next word (not yet used)
+ NEXT_WORD
+ };
+
}
#endif // LYX_TYPES_H
#include "language.h"
#include "ParagraphParameters.h"
#include "undo_funcs.h"
+#include "text_funcs.h"
#include "WordLangTuple.h"
#include "paragraph_funcs.h"
#include "rowpainter.h"
using std::min;
using std::endl;
using std::pair;
+
using lyx::pos_type;
+using lyx::word_location;
+
using namespace bv_funcs;
/// top, right, bottom pixel margin
void LyXText::cursorRightOneWord()
{
- // treat floats, HFills and Insets as words
- ParagraphList::iterator pit = cursor.par();
- pos_type pos = cursor.pos();
-
- // CHECK See comment on top of text.C
-
- if (pos == pit->size()
- && boost::next(pit) != ownerParagraphs().end()) {
- ++pit;
- pos = 0;
- } else {
- // Skip through initial nonword stuff.
- while (pos < pit->size() && !pit->isWord(pos)) {
- ++pos;
- }
- // Advance through word.
- while (pos < pit->size() && pit->isWord(pos)) {
- ++pos;
- }
- }
- setCursor(pit, pos);
+ ::cursorRightOneWord(cursor, ownerParagraphs());
+ setCursor(cursor.par(), cursor.pos());
}
void LyXText::cursorLeftOneWord()
{
LyXCursor tmpcursor = cursor;
- cursorLeftOneWord(tmpcursor);
+ ::cursorLeftOneWord(tmpcursor, ownerParagraphs());
setCursor(tmpcursor.par(), tmpcursor.pos());
}
-void LyXText::cursorLeftOneWord(LyXCursor & cur)
-{
- // treat HFills, floats and Insets as words
-
- ParagraphList::iterator pit = cursor.par();
- pos_type pos = cursor.pos();
-
- while (pos &&
- (pit->isSeparator(pos - 1) ||
- pit->isKomma(pos - 1) ||
- pit->isNewline(pos - 1)) &&
- !(pit->isHfill(pos - 1) ||
- pit->isInset(pos - 1)))
- --pos;
-
- if (pos &&
- (pit->isInset(pos - 1) ||
- pit->isHfill(pos - 1))) {
- --pos;
- } else if (!pos) {
- if (pit != ownerParagraphs().begin()) {
- --pit;
- pos = pit->size();
- }
- } else { // Here, cur != 0
- while (pos > 0 &&
- pit->isWord(pos - 1))
- --pos;
- }
-
- cur.par(pit);
- cur.pos(pos);
-}
-
-
-// Select current word. This depends on behaviour of
-// CursorLeftOneWord(), so it is patched as well.
-void LyXText::getWord(LyXCursor & from, LyXCursor & to,
- word_location const loc)
-{
- // first put the cursor where we wana start to select the word
- from = cursor;
- switch (loc) {
- case WHOLE_WORD_STRICT:
- if (cursor.pos() == 0 || cursor.pos() == cursor.par()->size()
- || cursor.par()->isSeparator(cursor.pos())
- || cursor.par()->isKomma(cursor.pos())
- || cursor.par()->isNewline(cursor.pos())
- || cursor.par()->isSeparator(cursor.pos() - 1)
- || cursor.par()->isKomma(cursor.pos() - 1)
- || cursor.par()->isNewline(cursor.pos() - 1)) {
- to = from;
- return;
- }
- // no break here, we go to the next
-
- case WHOLE_WORD:
- // Move cursor to the beginning, when not already there.
- if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
- && !(from.par()->isKomma(from.pos() - 1)
- || from.par()->isNewline(from.pos() - 1)))
- cursorLeftOneWord(from);
- break;
- case PREVIOUS_WORD:
- // always move the cursor to the beginning of previous word
- cursorLeftOneWord(from);
- break;
- case NEXT_WORD:
- lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet\n";
- break;
- case PARTIAL_WORD:
- break;
- }
- to = from;
- while (to.pos() < to.par()->size()
- && !to.par()->isSeparator(to.pos())
- && !to.par()->isKomma(to.pos())
- && !to.par()->isNewline(to.pos())
- && !to.par()->isHfill(to.pos())
- && !to.par()->isInset(to.pos()))
- {
- to.pos(to.pos() + 1);
- }
-}
-
-
void LyXText::selectWord(word_location loc)
{
- LyXCursor from;
+ LyXCursor from = cursor;
LyXCursor to;
- getWord(from, to, loc);
+ ::getWord(from, to, loc, ownerParagraphs());
if (cursor != from)
setCursor(from.par(), from.pos());
if (to == from)
from = selection.start;
to = selection.end;
} else {
- getWord(from, to, PARTIAL_WORD);
+ from = cursor;
+ ::getWord(from, to, lyx::PARTIAL_WORD, ownerParagraphs());
setCursor(to.par(), to.pos() + 1);
}
LyXCursor resetCursor = cursor;
bool implicitSelection = (font.language() == ignore_language
&& font.number() == LyXFont::IGNORE)
- ? selectWordWhenUnderCursor(WHOLE_WORD_STRICT) : false;
+ ? selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT) : false;
// Set font
setFont(font, toggleall);
// If there is a change in the language the implicit word selection
// is disabled.
LyXCursor const reset_cursor = cursor;
- bool const implicitSelection = selectWordWhenUnderCursor(PREVIOUS_WORD);
+ bool const implicitSelection =
+ selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
string idxstring;
if (!selection.set())
case LFUN_WORDSEL: {
update();
- LyXCursor cur1;
+ LyXCursor cur1 = cursor;
LyXCursor cur2;
- getWord(cur1, cur2, WHOLE_WORD);
+ ::getWord(cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
setCursor(cur1.par(), cur1.pos());
bv->beforeChange(this);
setCursor(cur2.par(), cur2.pos());
case LFUN_TRANSPOSE_CHARS:
update();
- transposeChars(*this, cursor);
+ setUndo(bv, Undo::FINISH, cursor.par());
+ if (transposeChars(cursor))
+ checkParagraph(cursor.par(), cursor.pos());
if (inset_owner)
bv->updateInset(inset_owner);
update();
if (cmd.button() == mouse_button::button1) {
if (!isInInset()) {
bv->screen().toggleSelection(this, bv);
- selectWord(LyXText::WHOLE_WORD_STRICT);
+ selectWord(lyx::WHOLE_WORD_STRICT);
bv->screen().toggleSelection(this, bv, false);
} else {
- selectWord(LyXText::WHOLE_WORD_STRICT);
+ selectWord(lyx::WHOLE_WORD_STRICT);
}
update();
bv->haveSelection(selection.set());
#include <config.h>
-#include "lyxtext.h"
-#include "paragraph.h"
+#include "debug.h"
#include "lyxcursor.h"
-#include "undo_funcs.h"
+#include "ParagraphList.h"
+
+#include "support/types.h"
#include <boost/next_prior.hpp>
using lyx::pos_type;
+using lyx::word_location;
+
-void transposeChars(LyXText & text, LyXCursor const & cursor)
+bool transposeChars(LyXCursor const & cursor)
{
ParagraphList::iterator tmppit = cursor.par();
-
- setUndo(text.bv(), Undo::FINISH, tmppit);
-
pos_type tmppos = cursor.pos();
// First decide if it is possible to transpose at all
if (tmppos == 0 || tmppos == tmppit->size())
- return;
+ return false;
if (isDeletedText(*tmppit, tmppos - 1)
|| isDeletedText(*tmppit, tmppos))
- return;
+ return false;
unsigned char c1 = tmppit->getChar(tmppos);
unsigned char c2 = tmppit->getChar(tmppos - 1);
// We should have an implementation that handles insets
// as well, but that will have to come later. (Lgb)
if (c1 == Paragraph::META_INSET || c2 == Paragraph::META_INSET)
- return;
+ return false;
bool const erased = tmppit->erase(tmppos - 1, tmppos + 1);
- pos_type const ipos(erased ? tmppos - 1 : tmppos + 1);
+ size_t const ipos = erased ? tmppos - 1 : tmppos + 1;
tmppit->insertChar(ipos, c1);
tmppit->insertChar(ipos + 1, c2);
+ return true;
+}
+
+
+void cursorLeftOneWord(LyXCursor & cursor, ParagraphList const & pars)
+{
+ // treat HFills, floats and Insets as words
+
+ ParagraphList::iterator pit = cursor.par();
+ size_t pos = cursor.pos();
+
+ while (pos &&
+ (pit->isSeparator(pos - 1) ||
+ pit->isKomma(pos - 1) ||
+ pit->isNewline(pos - 1)) &&
+ !(pit->isHfill(pos - 1) ||
+ pit->isInset(pos - 1)))
+ --pos;
+
+ if (pos &&
+ (pit->isInset(pos - 1) ||
+ pit->isHfill(pos - 1))) {
+ --pos;
+ } else if (!pos) {
+ if (pit != pars.begin()) {
+ --pit;
+ pos = pit->size();
+ }
+ } else { // Here, cur != 0
+ while (pos > 0 && pit->isWord(pos - 1))
+ --pos;
+ }
+
+ cursor.par(pit);
+ cursor.pos(pos);
+}
+
+
+void cursorRightOneWord(LyXCursor & cursor, ParagraphList const & pars)
+{
+ // treat floats, HFills and Insets as words
+ ParagraphList::iterator pit = cursor.par();
+ pos_type pos = cursor.pos();
+
+ // CHECK See comment on top of text.C
+
+ if (pos == pit->size() && boost::next(pit) != pars.end()) {
+ ++pit;
+ pos = 0;
+ } else {
+ // Skip through initial nonword stuff.
+ while (pos < pit->size() && !pit->isWord(pos)) {
+ ++pos;
+ }
+ // Advance through word.
+ while (pos < pit->size() && pit->isWord(pos)) {
+ ++pos;
+ }
+ }
+
+ cursor.par(pit);
+ cursor.pos(pos);
+}
+
+
+// Select current word. This depends on behaviour of
+// CursorLeftOneWord(), so it is patched as well.
+void getWord(LyXCursor & from, LyXCursor & to, word_location const loc,
+ ParagraphList const & pars)
+{
+ switch (loc) {
+ case lyx::WHOLE_WORD_STRICT:
+ if (from.pos() == 0 || from.pos() == from.par()->size()
+ || from.par()->isSeparator(from.pos())
+ || from.par()->isKomma(from.pos())
+ || from.par()->isNewline(from.pos())
+ || from.par()->isSeparator(from.pos() - 1)
+ || from.par()->isKomma(from.pos() - 1)
+ || from.par()->isNewline(from.pos() - 1)) {
+ to = from;
+ return;
+ }
+ // no break here, we go to the next
- text.checkParagraph(tmppit, tmppos);
+ case lyx::WHOLE_WORD:
+ // Move cursor to the beginning, when not already there.
+ if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
+ && !(from.par()->isKomma(from.pos() - 1)
+ || from.par()->isNewline(from.pos() - 1)))
+ cursorLeftOneWord(from, pars);
+ break;
+ case lyx::PREVIOUS_WORD:
+ // always move the cursor to the beginning of previous word
+ cursorLeftOneWord(from, pars);
+ break;
+ case lyx::NEXT_WORD:
+ lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet\n";
+ break;
+ case lyx::PARTIAL_WORD:
+ break;
+ }
+ to = from;
+ while (to.pos() < to.par()->size()
+ && !to.par()->isSeparator(to.pos())
+ && !to.par()->isKomma(to.pos())
+ && !to.par()->isNewline(to.pos())
+ && !to.par()->isHfill(to.pos())
+ && !to.par()->isInset(to.pos()))
+ {
+ to.pos(to.pos() + 1);
+ }
}
#include <config.h>
-class LyXText;
+#include "support/types.h"
+
class LyXCursor;
+class ParagraphList;
+
+
+// do no use LyXText or BufferView here
+
+
+///
+bool transposeChars(LyXCursor const & cursor);
+///
+void cursorLeftOneWord(LyXCursor &, ParagraphList const &);
+///
+void cursorRightOneWord(LyXCursor &, ParagraphList const &);
-void transposeChars(LyXText & text, LyXCursor const & cursor);
+// Select current word. This depends on behaviour of
+// CursorLeftOneWord(), so it is patched as well.
+void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const loc,
+ ParagraphList const & pars);
#endif // TEXT_FUNCS_H
#ifndef TEXTCURSOR_H
#define TEXTCURSOR_H
+// Do not even think of forward declaring LyXText/BufferView etc here!
+// If you need Paragraph proper, go to text_func.h
+
/** The cursor.
Later this variable has to be removed. There should be now internal
cursor in a text (and thus not in a buffer). By keeping this it is