mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-11 03:03:06 +00:00
fix table crash;
selection by mouse git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8617 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
9b35643f8e
commit
6c9b23105c
@ -861,7 +861,6 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
|
||||
//lyxerr << "*** workAreaDispatch: request: " << cmd << std::endl;
|
||||
LCursor cur(*bv_);
|
||||
cur.push(bv_->buffer()->inset());
|
||||
cur.resetAnchor();
|
||||
cur.selection() = bv_->cursor().selection();
|
||||
|
||||
// Doesn't go through lyxfunc, so we need to update
|
||||
@ -873,14 +872,17 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
|
||||
|
||||
screen().hideCursor();
|
||||
|
||||
// either the inset under the cursor or the
|
||||
// Either the inset under the cursor or the
|
||||
// surrounding LyXText will handle this event.
|
||||
|
||||
// built temporary path to inset
|
||||
// Build temporary cursor.
|
||||
InsetBase * inset = bv_->text()->editXY(cur, cmd.x, cmd.y);
|
||||
lyxerr << "hit inset at tip: " << inset << endl;
|
||||
lyxerr << "created temp cursor:\n" << cur << endl;
|
||||
|
||||
// Put anchor at the same position.
|
||||
cur.resetAnchor();
|
||||
|
||||
// Try to dispatch to an non-editable inset near this position
|
||||
// via the temp cursor. If the inset wishes to change the real
|
||||
// cursor it has to do so explicitly by using
|
||||
@ -889,16 +891,11 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
|
||||
if (inset)
|
||||
inset->dispatch(cur, cmd);
|
||||
|
||||
// Now dispatch to the real cursor. Any change to the cursor
|
||||
// is immediate.
|
||||
// Now dispatch to the temporary cursor. If the real cursor should
|
||||
// be modified, the inset's dispatch has to do so explicitly.
|
||||
if (!res.dispatched())
|
||||
res = cur.dispatch(cmd);
|
||||
|
||||
// If the request was dispatched the temp cursor should have been
|
||||
// in a way to be used as new 'real' cursor.
|
||||
if (res.dispatched())
|
||||
bv_->cursor() = cur;
|
||||
|
||||
// Redraw if requested or necessary.
|
||||
if (res.update())
|
||||
update();
|
||||
|
24
src/cursor.C
24
src/cursor.C
@ -316,15 +316,27 @@ bool LCursor::posRight()
|
||||
|
||||
CursorSlice & LCursor::anchor()
|
||||
{
|
||||
if (anchor_.size() < size()) {
|
||||
lyxerr << "anchor_.size() < cursor_.size() "
|
||||
"should not happen when accessing the anchor" << endl;
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
BOOST_ASSERT(!anchor_.empty());
|
||||
return anchor_.back();
|
||||
// this size is cursor_.size()
|
||||
return anchor_[size() - 1];
|
||||
}
|
||||
|
||||
|
||||
CursorSlice const & LCursor::anchor() const
|
||||
{
|
||||
if (anchor_.size() < size()) {
|
||||
lyxerr << "anchor_.size() < cursor_.size() "
|
||||
"should not happen when accessing the anchor" << endl;
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
// this size is cursor_.size()
|
||||
BOOST_ASSERT(!anchor_.empty());
|
||||
return anchor_.back();
|
||||
return anchor_[size() - 1];
|
||||
}
|
||||
|
||||
|
||||
@ -364,6 +376,7 @@ void LCursor::setSelection()
|
||||
{
|
||||
selection() = true;
|
||||
// a selection with no contents is not a selection
|
||||
#warning doesnt look ok
|
||||
if (par() == anchor().par() && pos() == anchor().pos())
|
||||
selection() = false;
|
||||
}
|
||||
@ -496,13 +509,6 @@ string LCursor::grabAndEraseSelection()
|
||||
}
|
||||
|
||||
|
||||
void LCursor::selClear()
|
||||
{
|
||||
resetAnchor();
|
||||
clearSelection();
|
||||
}
|
||||
|
||||
|
||||
void LCursor::selCopy()
|
||||
{
|
||||
if (selection()) {
|
||||
|
@ -96,10 +96,6 @@ public:
|
||||
void selPaste(size_t n);
|
||||
///
|
||||
void selHandle(bool selecting);
|
||||
/// start selection
|
||||
void selStart();
|
||||
/// clear selection
|
||||
void selClear();
|
||||
/// clears or deletes selection depending on lyxrc setting
|
||||
void selClearOrDel();
|
||||
//
|
||||
|
@ -150,7 +150,7 @@ bool operator<(CursorSlice const & p, CursorSlice const & q)
|
||||
if (&p.inset() != &q.inset()) {
|
||||
lyxerr << "can't compare cursor and anchor in different insets\n"
|
||||
<< "p: " << p << '\n' << "q: " << q << endl;
|
||||
return true;
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
if (p.idx() != q.idx())
|
||||
return p.idx() < q.idx();
|
||||
|
@ -103,6 +103,7 @@ MathAtom & DocIterator::prevAtom()
|
||||
MathAtom const & DocIterator::nextAtom() const
|
||||
{
|
||||
BOOST_ASSERT(!empty());
|
||||
lyxerr << "lastpos: " << lastpos() << " next atom:\n" << *this << endl;
|
||||
BOOST_ASSERT(pos() < lastpos());
|
||||
return cell()[pos()];
|
||||
}
|
||||
@ -111,6 +112,7 @@ MathAtom const & DocIterator::nextAtom() const
|
||||
MathAtom & DocIterator::nextAtom()
|
||||
{
|
||||
BOOST_ASSERT(!empty());
|
||||
lyxerr << "lastpos: " << lastpos() << " next atom:\n" << *this << endl;
|
||||
BOOST_ASSERT(pos() < lastpos());
|
||||
return cell()[pos()];
|
||||
}
|
||||
|
@ -410,6 +410,7 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd)
|
||||
lyxerr << "# InsetTabular::dispatch: cmd: " << cmd << endl;
|
||||
//lyxerr << " cur:\n" << cur << endl;
|
||||
CursorSlice sl = cur.top();
|
||||
LCursor & bvcur = cur.bv().cursor();
|
||||
|
||||
switch (cmd.action) {
|
||||
|
||||
@ -420,7 +421,7 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd)
|
||||
cur.selection() = false;
|
||||
setPos(cur, cmd.x, cmd.y);
|
||||
cur.resetAnchor();
|
||||
cur.bv().cursor().setCursor(cur, false);
|
||||
bvcur = cur;
|
||||
//if (cmd.button() == mouse_button::button2)
|
||||
// dispatch(cur, FuncRequest(LFUN_PASTESELECTION, "paragraph"));
|
||||
//lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
|
||||
@ -429,13 +430,16 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd)
|
||||
case LFUN_MOUSE_MOTION:
|
||||
if (cmd.button() != mouse_button::button1)
|
||||
break;
|
||||
// ignore motions deeper nested than the real anchor
|
||||
if (bvcur.selection() && bvcur.anchor_.size() < cur.size())
|
||||
break;
|
||||
setPos(cur, cmd.x, cmd.y);
|
||||
cur.bv().cursor().setCursor(cur, true);
|
||||
//lyxerr << "# InsetTabular::MouseMotion\n" << cur.bv().cursor() << endl;
|
||||
bvcur.setCursor(cur, true);
|
||||
//lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl;
|
||||
break;
|
||||
|
||||
case LFUN_MOUSE_RELEASE:
|
||||
//lyxerr << "# InsetTabular::MouseRelease\n" << cur.bv().cursor() << endl;
|
||||
//lyxerr << "# InsetTabular::MouseRelease\n" << bvcur << endl;
|
||||
if (cmd.button() == mouse_button::button3)
|
||||
InsetTabularMailer(*this).showDialog(&cur.bv());
|
||||
break;
|
||||
@ -1725,7 +1729,7 @@ void InsetTabular::addPreview(PreviewLoader & loader) const
|
||||
|
||||
bool InsetTabular::tablemode(LCursor & cur) const
|
||||
{
|
||||
return cur.selBegin().idx() != cur.selEnd().idx();
|
||||
return cur.selection() && cur.selBegin().idx() != cur.selEnd().idx();
|
||||
}
|
||||
|
||||
|
||||
|
@ -511,6 +511,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
|
||||
flag.enabled(false);
|
||||
}
|
||||
|
||||
//lyxerr << "LyXFunc::getStatus: got: " << flag.enabled() << endl;
|
||||
return flag;
|
||||
}
|
||||
|
||||
@ -1257,13 +1258,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_BREAKLINE: {
|
||||
#ifdef WITH_WARNINGS
|
||||
#warning swallow 'Return' if the minibuffer is focused. But how?
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_ALL_INSETS_TOGGLE: {
|
||||
string action;
|
||||
string const name = split(argument, action, ' ');
|
||||
|
@ -783,7 +783,7 @@ void MathHullInset::doExtern(LCursor & cur, FuncRequest & func)
|
||||
|
||||
void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
|
||||
{
|
||||
lyxerr << "*** MathHullInset: request: " << cmd << endl;
|
||||
//lyxerr << "*** MathHullInset: request: " << cmd << endl;
|
||||
switch (cmd.action) {
|
||||
|
||||
case LFUN_BREAKLINE:
|
||||
|
@ -571,7 +571,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
|
||||
|
||||
case LFUN_ESCAPE:
|
||||
if (cur.selection())
|
||||
cur.selClear();
|
||||
cur.clearSelection();
|
||||
else
|
||||
cmd = FuncRequest(LFUN_FINISHED_LEFT);
|
||||
break;
|
||||
@ -964,7 +964,7 @@ void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
|
||||
if (cmd.button() == mouse_button::button2) {
|
||||
MathArray ar;
|
||||
asArray(cur.bv().getClipboard(), ar);
|
||||
cur.selClear();
|
||||
cur.clearSelection();
|
||||
cur.setScreenPos(cmd.x, cmd.y);
|
||||
cur.insert(ar);
|
||||
cur.bv().update();
|
||||
@ -987,9 +987,9 @@ void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd)
|
||||
if (cmd.button() == mouse_button::button1) {
|
||||
first_x = cmd.x;
|
||||
first_y = cmd.y;
|
||||
cur.selClear();
|
||||
//cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
|
||||
lyxerr << "lfunMousePress: setting cursor to: " << cur << endl;
|
||||
cur.resetAnchor();
|
||||
cur.bv().cursor() = cur;
|
||||
}
|
||||
|
||||
@ -1011,10 +1011,6 @@ void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd)
|
||||
first_x = cmd.x;
|
||||
first_y = cmd.y;
|
||||
|
||||
if (!cur.selection())
|
||||
cur.selBegin();
|
||||
|
||||
//cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
|
||||
cur.bv().cursor().setCursor(cur, true);
|
||||
}
|
||||
|
||||
|
@ -1671,14 +1671,14 @@ void Paragraph::cleanChanges()
|
||||
|
||||
Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
|
||||
{
|
||||
BOOST_ASSERT(!size() || pos < size());
|
||||
BOOST_ASSERT(empty() || pos < size());
|
||||
return pimpl_->lookupChange(pos);
|
||||
}
|
||||
|
||||
|
||||
Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
|
||||
{
|
||||
BOOST_ASSERT(!size() || pos < size());
|
||||
BOOST_ASSERT(empty() || pos < size());
|
||||
return pimpl_->lookupChangeFull(pos);
|
||||
}
|
||||
|
||||
|
14
src/text2.C
14
src/text2.C
@ -417,12 +417,18 @@ void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall)
|
||||
DocIterator pos = cur.selectionBegin();
|
||||
DocIterator posend = cur.selectionEnd();
|
||||
|
||||
lyxerr << "pos: " << pos << " posend: " << posend << endl;
|
||||
|
||||
BufferParams const & params = bv()->buffer()->params();
|
||||
|
||||
for (; pos != posend; pos.forwardChar()) {
|
||||
LyXFont f = getFont(pos.par(), pos.pos());
|
||||
f.update(font, params.language, toggleall);
|
||||
setCharFont(pos.par(), pos.pos(), f);
|
||||
// Don't use forwardChar here as posend might have
|
||||
// pos() == lastpos() and forwardChar would miss it.
|
||||
for (; pos != posend; pos.forwardPos()) {
|
||||
if (pos.pos() != pos.lastpos()) {
|
||||
LyXFont f = getFont(pos.par(), pos.pos());
|
||||
f.update(font, params.language, toggleall);
|
||||
setCharFont(pos.par(), pos.pos(), f);
|
||||
}
|
||||
}
|
||||
|
||||
redoParagraphs(beg, end + 1);
|
||||
|
13
src/text3.C
13
src/text3.C
@ -138,7 +138,7 @@ namespace {
|
||||
|
||||
if (sel.empty()) {
|
||||
cur.insert(new MathHullInset);
|
||||
cur.dispatch(FuncRequest(LFUN_RIGHT));
|
||||
cur.nextInset()->edit(cur, true);
|
||||
cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
|
||||
// don't do that also for LFUN_MATH_MODE unless you want end up with
|
||||
// always changing to mathrm when opening an inlined inset
|
||||
@ -1079,6 +1079,12 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
|
||||
lyxerr << "BufferView::Pimpl::dispatch: no selection possible\n";
|
||||
break;
|
||||
}
|
||||
|
||||
// ignore motions deeper nested than the real anchor
|
||||
LCursor & bvcur = cur.bv().cursor();
|
||||
if (bvcur.selection() && bvcur.anchor_.size() < cur.size())
|
||||
break;
|
||||
|
||||
CursorSlice old = cur.top();
|
||||
setCursorFromCoordinates(cur, cmd.x, cmd.y);
|
||||
|
||||
@ -1140,6 +1146,10 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
|
||||
finishUndo();
|
||||
cur.x_target() = cursorX(cur.top());
|
||||
|
||||
// Set cursor here.
|
||||
bv->cursor() = cur;
|
||||
|
||||
// Don't allow selection after a big jump.
|
||||
if (bv->fitCursor())
|
||||
selection_possible = false;
|
||||
|
||||
@ -1153,6 +1163,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
|
||||
bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
|
||||
selection_possible = false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user