#include "lyxtext.h"
#include "paragraph.h"
#include "paragraph_funcs.h"
+#include "PosIterator.h"
#include "texrow.h"
#include "undo.h"
#include "WordLangTuple.h"
string const fname = MakeAbsPath(filen);
- text()->clearSelection();
+ clearSelection();
text()->breakParagraph(buffer()->paragraphs());
bool res = buffer()->readFile(fname, text()->cursorPar());
vector<string> labels;
it->getLabelList(*buffer(), labels);
if (find(labels.begin(),labels.end(),label) != labels.end()) {
- text()->clearSelection();
+ clearSelection();
text()->setCursor(
std::distance(text()->paragraphs().begin(), it.getPar()),
it.getPos());
return;
owner()->message(_("Undo"));
- text()->clearSelection();
+ clearSelection();
if (!textUndo(this))
owner()->message(_("No further undo information"));
update();
return;
owner()->message(_("Redo"));
- text()->clearSelection();
+ clearSelection();
if (!textRedo(this))
owner()->message(_("No further redo information"));
update();
return cursor();
return anchor() > cursor() ? anchor() : cursor();
}
+
+
+void BufferView::setSelection()
+{
+ selection().set(true);
+ // a selection with no contents is not a selection
+ if (cursor().par() == anchor().par() && cursor().pos() == anchor().pos())
+ selection().set(false);
+}
+
+
+void BufferView::clearSelection()
+{
+ selection().set(false);
+ selection().mark(false);
+ resetAnchor();
+ unsetXSel();
+}
+
+
+
+/*
+if the fitCursor call refers to some point in never-explored-land, then we
+don't have y information in insets there, then we cannot even do an update
+to get it (because we need the y infomation for setting top_y first). So
+this is solved in put_selection_at with:
+
+- setting top_y to the y of the outerPar (that has good info)
+- calling update
+- calling cursor().updatePos()
+- then call fitCursor()
+
+Ab.
+*/
+
+void BufferView::putSelectionAt(PosIterator const & cur,
+ int length, bool backwards)
+{
+ ParIterator par(cur);
+
+ clearSelection();
+
+ LyXText * text = par.text(*buffer());
+ par.lockPath(this);
+ // hack for the chicken and egg problem
+ if (par.inset())
+ top_y(par.outerPar()->y);
+ update();
+ text->setCursor(cur.pit(), cur.pos());
+ fullCursor().updatePos();
+
+ if (length) {
+ text->setSelectionRange(length);
+ setSelection();
+ if (backwards)
+ std::swap(cursor(), anchor());
+ }
+
+ fitCursor();
+ update();
+}
+
class LyXScreen;
class LyXView;
class Painter;
+class PosIterator;
class Selection;
class TeXErrors;
class UpdatableInset;
/// replace the currently selected word
void replaceWord(std::string const & replacestring);
+ /// simple replacing. Use the font of the first selected character
+ void replaceSelectionWithString(std::string const & str);
/// move cursor to the named label
void gotoLabel(std::string const & label);
CursorSlice & selEnd();
///
CursorSlice const & selEnd() const;
+ ///
+ void setSelection();
+ ///
+ void clearSelection();
+ ///
+ void putSelectionAt(PosIterator const & cur, int length, bool backwards);
///
Selection selection_;
text->setCursor(selstartpar, selstartpos);
bv_->resetAnchor();
text->setCursor(selendpar, selendpos);
- text->setSelection();
+ bv_->setSelection();
text->setCursor(par, pos);
} else {
text->setCursor(par, pos);
{
if (available()) {
screen().hideCursor();
- bv_->getLyXText()->clearSelection();
+ bv_->clearSelection();
xsel_cache_.set = false;
}
}
string const fname = saved_positions[i].filename;
- bv_->text()->clearSelection();
+ bv_->clearSelection();
if (fname != buffer_->fileName()) {
Buffer * b = 0;
{
LyXText * text = bv_->text();
- text->clearSelection();
+ bv_->clearSelection();
int const half_height = workarea().workHeight() / 2;
int new_y = std::max(0, text->cursorY() - half_height);
// should work for now. Better infrastructure is coming. (Lgb)
Buffer * b = bv_->buffer();
- LyXText * text = bv_->getLyXText();
+ LyXText * text = bv_->getLyXText();
Buffer::inset_iterator beg = b->inset_iterator_begin();
Buffer::inset_iterator end = b->inset_iterator_end();
lyx::find::replace(ev);
break;
+ case LFUN_MARK_OFF:
+ bv_->clearSelection();
+ bv_->update();
+ bv_->resetAnchor();
+ ev.message(N_("Mark off"));
+ break;
+
+ case LFUN_MARK_ON:
+ bv_->clearSelection();
+ bv_->selection().mark(true);
+ bv_->update();
+ bv_->resetAnchor();
+ ev.message(N_("Mark on"));
+ break;
+
+ case LFUN_SETMARK:
+ bv_->clearSelection();
+ if (bv_->selection().mark()) {
+ ev.message(N_("Mark removed"));
+ } else {
+ bv_->selection().mark(true);
+ ev.message(N_("Mark set"));
+ }
+ bv_->resetAnchor();
+ bv_->update();
+ break;
+
case LFUN_UNKNOWN_ACTION:
ev.errorMessage(N_("Unknown function!"));
break;
bv_->text()->recUndo(bv_->text()->cursor().par());
freezeUndo();
- bv_->text()->clearSelection();
+ bv_->clearSelection();
if (!lout.empty()) {
bv_->text()->breakParagraph(bv_->buffer()->paragraphs());
#include "buffer.h"
#include "BufferView.h"
+#include "cursor_slice.h"
#include "iterators.h"
#include "lyxtext.h"
#include "paragraph.h"
using boost::prior;
+
PosIterator & PosIterator::operator++()
{
BOOST_ASSERT(!stack_.empty());
PosIterator::PosIterator(BufferView & bv)
{
LyXText * text = bv.getLyXText();
- lyx::pos_type pos = text->cursor().pos();
+ lyx::pos_type pos = bv.cursor().pos();
ParagraphList::iterator pit = text->cursorPar();
ParIterator par = bv.buffer()->par_iterator_begin();
#include "lyxrow.h"
#include "paragraph.h"
#include "ParagraphParameters.h"
-#include "PosIterator.h"
#include "iterators.h"
#include "frontends/Alert.h"
}
}
-
-/*
-if the fitCursor call refers to some point in never-explored-land, then we
-don't have y information in insets there, then we cannot even do an update
-to get it (because we need the y infomation for setting top_y first). So
-this is solved in put_selection_at with:
-
-- setting top_y to the y of the outerPar (that has good info)
-- calling update
-- calling cursor().updatePos()
-- then call fitCursor()
-
-Ab.
-*/
-
-void put_selection_at(BufferView * bv, PosIterator const & cur,
- int length, bool backwards)
-{
- ParIterator par(cur);
-
- bv->getLyXText()->clearSelection();
-
- LyXText * text = par.text(*bv->buffer());
- par.lockPath(bv);
- // hack for the chicken and egg problem
- if (par.inset())
- bv->top_y(par.outerPar()->y);
- bv->update();
- text->setCursor(cur.pit(), cur.pos());
- bv->fullCursor().updatePos();
-
- if (length) {
- text->setSelectionRange(length);
- text->setSelection();
- if (backwards)
- std::swap(text->cursor(), text->anchor());
- }
-
- bv->fitCursor();
- bv->update();
-}
-
-
} // namespace bv_funcs
* frontends.
*/
std::string const freefont2string();
-///
-void put_selection_at(BufferView * bv, PosIterator const & cur,
- int length, bool backwards);
/// what type of depth change to make
#include "ControlErrorList.h"
#include "buffer.h"
#include "BufferView.h"
-#include "bufferview_funcs.h"
#include "debug.h"
#include "iterators.h"
#include "lyxtext.h"
// Now make the selection.
PosIterator const pos = pit.asPosIterator(start);
- bv_funcs::put_selection_at(kernel().bufferview(), pos, range, false);
+ kernel().bufferview()->putSelectionAt(pos, range, false);
}
if (!word_.word().empty()) {
int const size = word_.word().size();
advance(cur, -size);
- bv_funcs::put_selection_at(bufferview(), cur, size, false);
+ bufferview()->putSelectionAt(cur, size, false);
advance(cur, size);
} else {
showSummary();
setPos(bv, cmd.x, cmd.y);
if (!hasSelection()) {
setSelection(actcell, actcell);
- tabular.getCellInset(actcell).text_.setSelection();
+ bv->setSelection();
} else {
bv->cursor().cell(actcell);
setSelection(sel_cell_start, actcell);
///
void updateLocal(BufferView *) const;
///
- bool insetAllowed(InsetOld::Code code) const { return true; }
+ bool insetAllowed(InsetOld::Code) const { return true; }
///
bool isTextInset() const { return true; }
/** returns true if, when outputing LaTeX, font changes should
int const par = left ? 0 : paragraphs().size() - 1;
int const pos = left ? 0 : paragraphs().back().size();
text_.setCursor(par, pos);
- text_.clearSelection();
+ bv->clearSelection();
finishUndo();
sanitizeEmptyText(bv);
updateLocal(bv);
lyxerr << "InsetText::edit xy" << endl;
old_par = -1;
text_.setCursorFromCoordinates(x - text_.xo_, y + bv->top_y() - text_.yo_);
- text_.clearSelection();
+ bv->clearSelection();
finishUndo();
sanitizeEmptyText(bv);
updateLocal(bv);
first->insertChar(first_par_size, ' ');
}
- text_.clearSelection();
+ bv->clearSelection();
mergeParagraph(bv->buffer()->params(), paragraphs(), first);
}
}
// clear the selection
if (bv->text() == bv->getLyXText())
- bv->text()->clearSelection();
+ bv->clearSelection();
if (asParagraph)
bv->getLyXText()->insertStringAsParagraphs(tmpstr);
else
#include "lyxfind.h"
#include "buffer.h"
+#include "cursor_slice.h"
#include "BufferView.h"
#include "debug.h"
#include "iterators.h"
using lyx::support::uppercase;
using lyx::support::split;
-using bv_funcs::put_selection_at;
-
using std::ostringstream;
using std::string;
}
}
pos_type length = end - pos;
- put_selection_at(bv, cur, length, true);
+ bv->putSelectionAt(cur, length, true);
return true;
}
: findBackwards(cur, beg, match);
if (found)
- put_selection_at(bv, cur, searchstr.length(), !fw);
+ bv->putSelectionAt(cur, searchstr.length(), !fw);
return found;
}
PosIterator beg = buf.pos_iterator_begin();
bv->text()->init(bv);
- put_selection_at(bv, beg, 0, false);
+ bv->putSelectionAt(beg, 0, false);
if (num)
buf.markDirty();
return num;
#define LYXTEXT_H
#include "bufferview_funcs.h"
-#include "cursor_slice.h"
#include "Bidi.h"
#include "layout.h"
#include "lyxfont.h"
/// access to the selection anchor
CursorSlice const & anchor() const;
- ///
- void setSelection();
- ///
- void clearSelection();
-
public:
///
int height;
// convenience function
void LyXText::redoParagraph()
{
- clearSelection();
+ bv()->clearSelection();
redoParagraph(cursorPar());
setCursorIntern(cursor().par(), cursor().pos());
}
return;
bv()->resetAnchor();
setCursor(to.par(), to.pos());
- setSelection();
+ bv()->setSelection();
}
recordUndo(Undo::INSERT, this, startc.par());
getPar(startc)->acceptChange(startc.pos(), endc.pos());
finishUndo();
- clearSelection();
+ bv()->clearSelection();
redoParagraph(getPar(startc));
setCursorIntern(startc.par(), 0);
}
recordUndo(Undo::INSERT, this, startc.par());
getPar(startc)->rejectChange(startc.pos(), endc.pos());
finishUndo();
- clearSelection();
+ bv()->clearSelection();
redoParagraph(getPar(startc));
setCursorIntern(startc.par(), 0);
}
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
bv()->resetAnchor();
cursor() = tmpcursor;
- setSelection();
+ bv()->setSelection();
cutSelection(true, false);
}
}
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
bv()->resetAnchor();
cursor() = tmpcursor;
- setSelection();
+ bv()->setSelection();
cutSelection(true, false);
}
}
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
bv()->resetAnchor();
cursor() = tmpcursor;
- setSelection();
+ bv()->setSelection();
// What is this test for ??? (JMarc)
if (!bv()->selection().set())
deleteWordForward();
{
return bv()->anchor();
}
-
-
-void LyXText::setSelection()
-{
- bv()->selection().set(true);
- // a selection with no contents is not a selection
- if (cursor().par() == anchor().par() && cursor().pos() == anchor().pos())
- bv()->selection().set(false);
-}
-
-
-void LyXText::clearSelection()
-{
- bv()->selection().set(false);
- bv()->selection().mark(false);
- bv()->resetAnchor();
- // reset this in the bv()!
- if (bv() && bv()->text())
- bv()->unsetXSel();
-}
-
// Implicit selections are cleared afterwards
//and cursor is set to the original position.
if (implicitSelection) {
- clearSelection();
+ bv()->clearSelection();
cursor() = resetCursor;
bv()->resetAnchor();
}
// Clear the implicit selection.
if (implicitSelection)
- clearSelection();
+ bv()->clearSelection();
return idxstring;
}
cursor().par(parOffset(endpit));
// need a valid cursor. (Lgb)
- clearSelection();
+ bv()->clearSelection();
updateCounters();
}
redoParagraphs(cursorPar(), endpit);
- clearSelection();
-
+ bv()->clearSelection();
bv()->resetAnchor();
setCursor(ppp.first, ppp.second);
- setSelection();
+ bv()->setSelection();
updateCounters();
}
bv()->resetAnchor();
while (length--)
cursorRight(true);
- setSelection();
+ bv()->setSelection();
}
recUndo(cursor().par());
// only to be sure, should not be neccessary
- clearSelection();
-
+ bv()->clearSelection();
bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
redoParagraphs(cursorPar(), endpit);
bv()->resetAnchor();
setCursor(pit, pos);
- setSelection();
+ bv()->setSelection();
}
return DispatchResult(true, true);
cursorRight(true);
if (!selecting)
- clearSelection();
+ bv()->clearSelection();
return DispatchResult(true);
}
return DispatchResult(false, FINISHED);
cursorLeft(true);
if (!selecting)
- clearSelection();
+ bv()->clearSelection();
if (activate_inset && checkAndActivateInset(front))
return DispatchResult(true, true);
return DispatchResult(true);
if (cursorPar() == firstPar() && cursorRow() == firstRow())
return DispatchResult(false, FINISHED_UP);
cursorUp(false);
- clearSelection();
+ bv()->clearSelection();
return DispatchResult(true);
}
if (cursorPar() == lastPar() && cursorRow() == lastRow())
return DispatchResult(false, FINISHED_DOWN);
cursorDown(false);
- clearSelection();
+ bv()->clearSelection();
return DispatchResult(true);
}
bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor)
{
+#warning Disabled as it crashes after the cursor data shift... (Andre)
+ return false;
+
// Would be wrong to delete anything if we have a selection.
if (bv()->selection().set())
return false;
void moveCursor(BufferView * bv, bool selecting)
{
- LyXText * lt = bv->getLyXText();
-
if (selecting || bv->selection().mark())
- lt->setSelection();
+ bv->setSelection();
if (!bv->selection().set())
bv->haveSelection(false);
void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
bool same_content)
{
- clearSelection();
+ bv()->clearSelection();
string contents;
if (same_content && cursor().pos() < cursorPar()->size()
}
case LFUN_DELETE_WORD_FORWARD:
- clearSelection();
+ bv->clearSelection();
deleteWordForward();
finishChange(bv);
break;
case LFUN_DELETE_WORD_BACKWARD:
- clearSelection();
+ bv->clearSelection();
deleteWordBackward();
finishChange(bv);
break;
case LFUN_DELETE_LINE_FORWARD:
- clearSelection();
+ bv->clearSelection();
deleteLineForward();
finishChange(bv);
break;
case LFUN_WORDRIGHT:
if (!bv->selection().mark())
- clearSelection();
+ bv->clearSelection();
if (rtl())
cursorLeftOneWord();
else
case LFUN_WORDLEFT:
if (!bv->selection().mark())
- clearSelection();
+ bv->clearSelection();
if (rtl())
cursorRightOneWord();
else
case LFUN_BEGINNINGBUF:
if (!bv->selection().mark())
- clearSelection();
+ bv->clearSelection();
cursorTop();
finishChange(bv);
break;
case LFUN_ENDBUF:
if (bv->selection().mark())
- clearSelection();
+ bv->clearSelection();
cursorBottom();
finishChange(bv);
break;
case LFUN_UP_PARAGRAPH:
if (!bv->selection().mark())
- clearSelection();
+ bv->clearSelection();
cursorUpParagraph();
finishChange(bv);
break;
case LFUN_DOWN_PARAGRAPH:
if (!bv->selection().mark())
- clearSelection();
+ bv->clearSelection();
cursorDownParagraph();
finishChange(bv, false);
break;
case LFUN_PRIOR:
if (!bv->selection().mark())
- clearSelection();
+ bv->clearSelection();
finishChange(bv, false);
if (cursorPar() == firstPar() && cursorRow() == firstRow())
return DispatchResult(false, FINISHED_UP);
case LFUN_NEXT:
if (!bv->selection().mark())
- clearSelection();
+ bv->clearSelection();
finishChange(bv, false);
if (cursorPar() == lastPar() && cursorRow() == lastRow())
return DispatchResult(false, FINISHED_DOWN);
case LFUN_HOME:
if (!bv->selection().mark())
- clearSelection();
+ bv->clearSelection();
cursorHome();
finishChange(bv, false);
break;
case LFUN_END:
if (!bv->selection().mark())
- clearSelection();
+ bv->clearSelection();
cursorEnd();
finishChange(bv, false);
break;
break;
case LFUN_INSET_TOGGLE:
- clearSelection();
+ bv->clearSelection();
if (!toggleInset())
return DispatchResult(false);
bv->update();
specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
break;
- case LFUN_MARK_OFF:
- clearSelection();
- bv->update();
- bv->resetAnchor();
- cmd.message(N_("Mark off"));
- break;
-
- case LFUN_MARK_ON:
- clearSelection();
- bv->selection().mark(true);
- bv->update();
- bv->resetAnchor();
- cmd.message(N_("Mark on"));
- break;
-
- case LFUN_SETMARK:
- clearSelection();
- if (bv->selection().mark()) {
- cmd.message(N_("Mark removed"));
- } else {
- bv->selection().mark(true);
- cmd.message(N_("Mark set"));
- }
- bv->resetAnchor();
- bv->update();
- break;
-
case LFUN_UPCASE_WORD:
changeCase(LyXText::text_uppercase);
bv->update();
pasteSelection(strToUnsignedInt(cmd.argument));
else
pasteSelection(0);
- clearSelection(); // bug 393
+ bv->clearSelection(); // bug 393
bv->update();
bv->switchKeyMap();
finishUndo();
}
case LFUN_PASTESELECTION: {
- // this was originally a bv->text->clearSelection(), i.e
- // the outermost LyXText!
- clearSelection();
+ bv->clearSelection();
string const clip = bv->getClipboard();
if (!clip.empty()) {
if (cmd.argument == "paragraph")
cursorHome();
bv->resetAnchor();
cursorEnd();
- setSelection();
+ bv->setSelection();
bv->haveSelection(bv->selection().set());
}
break;
else if (cmd.y - bv->top_y() < 0)
cursorUp(true);
}
- setSelection();
+ bv->setSelection();
break;
}
selection_possible = true;
// Clear the selection
- clearSelection();
+ bv->clearSelection();
// Right click on a footnote flag opens float menu
if (cmd.button() == mouse_button::button3) {
bv->haveSelection(false);
}
- clearSelection();
+ bv->clearSelection();
LyXFont const old_font = real_current_font;
string::const_iterator cit = cmd.argument.begin();
#include "undo.h"
#include "buffer.h"
+#include "cursor_slice.h"
#include "debug.h"
#include "BufferView.h"
#include "iterators.h"
<< std::endl;
// set cursor again to force the position to be the right one
- text->cursor().par(undo.cursor_par);
- text->cursor().pos(undo.cursor_pos);
+ bv->cursor().par(undo.cursor_par);
+ bv->cursor().pos(undo.cursor_pos);
// clear any selection
- text->clearSelection();
+ bv->clearSelection();
bv->resetAnchor();
text->updateCounters();
advance(last, plist.size() - undo.end_par + 1);
otherstack.top().pars.insert(otherstack.top().pars.begin(), first, last);
}
- LyXText * text = pit.text(buf);
- otherstack.top().cursor_pos = text->cursor().pos();
- otherstack.top().cursor_par = text->cursor().par();
+ otherstack.top().cursor_pos = bv->cursor().pos();
+ otherstack.top().cursor_par = bv->cursor().par();
lyxerr << " undo other: " << otherstack.top() << std::endl;
}