mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-06 00:10:59 +00:00
last Friday's text*.C -> text_func shuffle
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7225 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
92d522b7f1
commit
aeba4e75c3
@ -1259,7 +1259,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
|
||||
// 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_) ?
|
||||
}
|
||||
|
@ -1,3 +1,14 @@
|
||||
|
||||
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
|
||||
|
@ -54,21 +54,6 @@ public:
|
||||
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
|
||||
@ -279,9 +264,9 @@ public:
|
||||
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;
|
||||
|
||||
@ -362,7 +347,7 @@ public:
|
||||
///
|
||||
void backspace();
|
||||
///
|
||||
bool selectWordWhenUnderCursor(word_location);
|
||||
bool selectWordWhenUnderCursor(lyx::word_location);
|
||||
///
|
||||
enum TextCase {
|
||||
///
|
||||
@ -451,8 +436,6 @@ public:
|
||||
private:
|
||||
///
|
||||
mutable RowList rowlist_;
|
||||
///
|
||||
void cursorLeftOneWord(LyXCursor &);
|
||||
|
||||
///
|
||||
float getCursorX(RowList::iterator rit, lyx::pos_type pos,
|
||||
|
@ -70,6 +70,21 @@ namespace lyx
|
||||
|
||||
#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
|
||||
|
122
src/text.C
122
src/text.C
@ -30,6 +30,7 @@
|
||||
#include "language.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "undo_funcs.h"
|
||||
#include "text_funcs.h"
|
||||
#include "WordLangTuple.h"
|
||||
#include "paragraph_funcs.h"
|
||||
#include "rowpainter.h"
|
||||
@ -49,7 +50,10 @@ using std::max;
|
||||
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
|
||||
@ -1976,27 +1980,8 @@ void LyXText::prepareToPrint(RowList::iterator rit, float & x,
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
@ -2005,102 +1990,16 @@ void LyXText::cursorRightOneWord()
|
||||
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)
|
||||
@ -2358,7 +2257,8 @@ void LyXText::changeCase(LyXText::TextCase action)
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -834,7 +834,7 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall)
|
||||
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);
|
||||
@ -858,7 +858,8 @@ string LyXText::getStringToIndex()
|
||||
// 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())
|
||||
|
12
src/text3.C
12
src/text3.C
@ -590,9 +590,9 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
|
||||
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());
|
||||
@ -1018,7 +1018,9 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
|
||||
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();
|
||||
@ -1268,10 +1270,10 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
|
||||
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());
|
||||
|
135
src/text_funcs.C
135
src/text_funcs.C
@ -14,31 +14,31 @@
|
||||
|
||||
#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);
|
||||
@ -46,13 +46,122 @@ void transposeChars(LyXText & text, LyXCursor const & cursor)
|
||||
// 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);
|
||||
|
||||
text.checkParagraph(tmppit, tmppos);
|
||||
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
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,25 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
class LyXText;
|
||||
class LyXCursor;
|
||||
#include "support/types.h"
|
||||
|
||||
void transposeChars(LyXText & text, LyXCursor const & cursor);
|
||||
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 &);
|
||||
|
||||
// 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
|
||||
|
@ -16,6 +16,9 @@
|
||||
#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
|
||||
|
Loading…
Reference in New Issue
Block a user