#include "bufferparams.h"
#include "BufferView.h"
#include "debug.h"
+#include "dispatchresult.h"
#include "encoding.h"
#include "funcrequest.h"
#include "gettext.h"
return font_metrics::width(c, font);
}
- if (c == Paragraph::META_INSET)
+ if (c == Paragraph::META_INSET)
return pit->getInset(pos)->width();
if (IsSeparatorChar(c))
pos_type addressBreakPoint(pos_type i, Paragraph const & par)
{
pos_type const end = par.size();
-
+
for (; i < end; ++i)
if (par.isNewline(i))
return i + 1;
row.endpos(end);
return;
}
-
+
// maximum pixel width of a row.
int width = workWidth() - rightMargin(*pit, *bv()->buffer());
// - leftMargin(pit, row);
point = i + 1;
break;
}
- // Break before...
+ // Break before...
if (i + 1 < end) {
InsetOld * in = pit->getInset(i + 1);
if (in && in->display()) {
}
char const c = pit->getChar(i);
-
+
if (i > endPosOfFontSpan) {
font = getFont(pit, i);
endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
}
-
+
{
int thiswidth = singleWidth(pit, i, c, font);
//<< x << " width: " << width << endl;
chunkwidth += thiswidth;
}
-
+
// break before a character that will fall off
// the right of the row
if (point == end || chunkwidth >= width - left) {
if (i > pos) {
point = i;
- break;
+ break;
}
}
// exit on last registered breakpoint:
// some insets are line separators too
if (pit->isLineSeparator(i)) {
// register breakpoint:
- point = i + 1;
+ point = i + 1;
chunkwidth = 0;
}
}
BufferParams const & bufparams = bv()->buffer()->params();
// some parksips VERY EASY IMPLEMENTATION
if (bv()->buffer()->params().paragraph_separation
- == BufferParams::PARSEP_SKIP
+ == BufferParams::PARSEP_SKIP
&& pit != ownerParagraphs().begin()
&& ((layout->isParagraph() && pit->getDepth() == 0)
|| (boost::prior(pit)->layout()->isParagraph()
// is it block, flushleft or flushright?
// set x how you need it
int align;
- if (pit->params().align() == LYX_ALIGN_LAYOUT) {
+ if (pit->params().align() == LYX_ALIGN_LAYOUT)
align = layout->align;
- } else {
+ else
align = pit->params().align();
- }
- // ERT insets should always be LEFT ALIGNED on screen
- InsetOld * inset = pit->inInset();
- if (inset && inset->owner() &&
- inset->owner()->lyxCode() == InsetOld::ERT_CODE)
- {
- align = LYX_ALIGN_LEFT;
- }
// Display-style insets should always be on a centred row
// The test on pit->size() is to catch zero-size pars, which
{
align = LYX_ALIGN_CENTER;
}
-
+
switch (align) {
case LYX_ALIGN_BLOCK: {
int const ns = numberOfSeparators(*pit, row);
}
-// This function is only used by the spellchecker for NextWord().
-// It doesn't handle LYX_ACCENTs and probably never will.
-WordLangTuple const LyXText::selectNextWordToSpellcheck(float & value)
-{
- if (the_locking_inset) {
- WordLangTuple word =
- the_locking_inset->selectNextWordToSpellcheck(bv(), value);
- if (!word.word().empty()) {
- value += float(cursor.y());
- value /= float(height);
- return word;
- }
- // we have to go on checking so move cursor to the next char
- if (cursor.pos() == cursorPar()->size()) {
- if (cursor.par() + 1 == int(ownerParagraphs().size()))
- return word;
- cursor.par(cursor.par() + 1);
- cursor.pos(0);
- } else {
- cursor.pos(cursor.pos() + 1);
- }
- }
- int const tmppar = cursor.par();
-
- // If this is not the very first word, skip rest of
- // current word because we are probably in the middle
- // of a word if there is text here.
- if (cursor.pos() || cursor.par() != 0) {
- while (cursor.pos() < cursorPar()->size()
- && cursorPar()->isLetter(cursor.pos()))
- cursor.pos(cursor.pos() + 1);
- }
-
- // Now, skip until we have real text (will jump paragraphs)
- while (true) {
- ParagraphList::iterator cpit = cursorPar();
- pos_type const cpos = cursor.pos();
-
- if (cpos == cpit->size()) {
- if (cursor.par() + 1 != int(ownerParagraphs().size())) {
- cursor.par(cursor.par() + 1);
- cursor.pos(0);
- continue;
- }
- break;
- }
-
- bool const is_good_inset = cpit->isInset(cpos)
- && cpit->getInset(cpos)->allowSpellcheck();
-
- if (!isDeletedText(*cpit, cpos)
- && (is_good_inset || cpit->isLetter(cpos)))
- break;
-
- cursor.pos(cpos + 1);
- }
-
- // now check if we hit an inset so it has to be a inset containing text!
- if (cursor.pos() < cursorPar()->size() &&
- cursorPar()->isInset(cursor.pos())) {
- // lock the inset!
- FuncRequest cmd(bv(), LFUN_INSET_EDIT, "left");
- cursorPar()->getInset(cursor.pos())->dispatch(cmd);
- // now call us again to do the above trick
- // but obviously we have to start from down below ;)
- return bv()->text->selectNextWordToSpellcheck(value);
- }
-
- // Update the value if we changed paragraphs
- if (cursor.par() != tmppar) {
- setCursor(cursor.par(), cursor.pos());
- value = float(cursor.y())/float(height);
- }
-
- // Start the selection from here
- selection.cursor = cursor;
-
- string lang_code = getFont(cursorPar(), cursor.pos()).language()->code();
- // and find the end of the word (insets like optional hyphens
- // and ligature break are part of a word)
- while (cursor.pos() < cursorPar()->size()
- && cursorPar()->isLetter(cursor.pos())
- && !isDeletedText(*cursorPar(), cursor.pos()))
- cursor.pos(cursor.pos() + 1);
-
- // Finally, we copy the word to a string and return it
- string str;
- if (selection.cursor.pos() < cursor.pos()) {
- for (pos_type i = selection.cursor.pos(); i < cursor.pos(); ++i) {
- if (!cursorPar()->isInset(i))
- str += cursorPar()->getChar(i);
- }
- }
- return WordLangTuple(str, lang_code);
-}
-
-
-// This one is also only for the spellchecker
-void LyXText::selectSelectedWord()
-{
- if (the_locking_inset) {
- the_locking_inset->selectSelectedWord(bv());
- return;
- }
- // move cursor to the beginning
- setCursor(selection.cursor.par(), selection.cursor.pos());
-
- // set the sel cursor
- selection.cursor = cursor;
-
- // now find the end of the word
- while (cursor.pos() < cursorPar()->size()
- && cursorPar()->isLetter(cursor.pos()))
- cursor.pos(cursor.pos() + 1);
-
- setCursor(cursorPar(), cursor.pos());
-
- // finally set the selection
- setSelection();
-}
-
-
// Delete from cursor up to the end of the current or next word.
void LyXText::deleteWordForward()
{
void LyXText::Delete()
{
// this is a very easy implementation
-
LyXCursor old_cursor = cursor;
- int const old_cur_par_id = cursorPar()->id();
- int const old_cur_par_prev_id =
- old_cursor.par() ? getPar(old_cursor.par() - 1)->id() : -1;
// just move to the right
cursorRight(bv());
- // CHECK Look at the comment here.
- // This check is not very good...
- // The cursorRightIntern calls DeleteEmptyParagraphMechanism
- // and that can very well delete the par or par->previous in
- // old_cursor. Will a solution where we compare paragraph id's
- //work better?
- int iid = cursor.par() ? getPar(cursor.par() - 1)->id() : -1;
- if (iid == old_cur_par_prev_id && cursorPar()->id() != old_cur_par_id) {
- // delete-empty-paragraph-mechanism has done it
- return;
- }
-
// if you had success make a backspace
if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
recordUndo(Undo::DELETE, this, old_cursor.par());
ParagraphList::iterator LyXText::cursorPar() const
{
+ return getPar(cursor.par());
+#warning have a look at this again later.
+ // We need some method to mark the cache as invalidated when
+ // the paragraph it points get removed, for this to work.
if (cursor.par() != cache_pos_) {
cache_pos_ = cursor.par();
cache_par_ = getPar(cache_pos_);