mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-31 07:45:44 +00:00
Simplify logic in InsetRef::latex().
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37958 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c6eca6e90b
commit
e52af5f897
@ -1,22 +1,22 @@
|
|||||||
# Inspired by #7363.
|
# Inspired by #7363.
|
||||||
#
|
#
|
||||||
Lang it_IT.utf8
|
Lang it_IT.utf8
|
||||||
TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
|
TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
|
||||||
KK: \Cm
|
KK: \Cm
|
||||||
KK: x_v \C\[Home]
|
KK: x_v \C\[Home]
|
||||||
KK: \Cs
|
KK: \Cs
|
||||||
KK: \CF
|
KK: \CF
|
||||||
KK: \Cm
|
KK: \Cm
|
||||||
KK: v\[Return]
|
KK: v\[Return]
|
||||||
TestEnd
|
TestEnd
|
||||||
Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 0\n.*idx: 1 par: 0 pos: 0\n with len: 1' lyx-log.txt
|
Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 0\n.*idx: 1 par: 0 pos: 0\n with len: 1' lyx-log.txt
|
||||||
|
|
||||||
TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
|
TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
|
||||||
KK: \C\[Home]
|
KK: \C\[Home]
|
||||||
KK: \CF
|
KK: \CF
|
||||||
# Uncheck ignore format
|
# Uncheck ignore format
|
||||||
KK: \Az\Ag\Ae
|
KK: \Az\Ag\Ae
|
||||||
KK: \Cm
|
KK: \Cm
|
||||||
KK: v\[Return]
|
KK: v\[Return]
|
||||||
TestEnd
|
TestEnd
|
||||||
Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 0\n.*idx: 1 par: 0 pos: 0\n with len: 1' lyx-log.txt
|
Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 0\n.*idx: 1 par: 0 pos: 0\n with len: 1' lyx-log.txt
|
||||||
|
@ -2364,42 +2364,6 @@ void BufferView::putSelectionAt(DocIterator const & cur,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool BufferView::selectIfEmpty(DocIterator & cur)
|
|
||||||
{
|
|
||||||
if (!cur.paragraph().empty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
pit_type const beg_pit = cur.pit();
|
|
||||||
if (beg_pit > 0) {
|
|
||||||
// The paragraph associated to this item isn't
|
|
||||||
// the first one, so it can be selected
|
|
||||||
cur.backwardPos();
|
|
||||||
} else {
|
|
||||||
// We have to resort to select the space between the
|
|
||||||
// end of this item and the begin of the next one
|
|
||||||
cur.forwardPos();
|
|
||||||
}
|
|
||||||
if (cur.empty()) {
|
|
||||||
// If it is the only item in the document,
|
|
||||||
// nothing can be selected
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
pit_type const end_pit = cur.pit();
|
|
||||||
pos_type const end_pos = cur.pos();
|
|
||||||
d->cursor_.clearSelection();
|
|
||||||
d->cursor_.reset();
|
|
||||||
d->cursor_.setCursor(cur);
|
|
||||||
d->cursor_.pit() = beg_pit;
|
|
||||||
d->cursor_.pos() = 0;
|
|
||||||
d->cursor_.setSelection(false);
|
|
||||||
d->cursor_.resetAnchor();
|
|
||||||
d->cursor_.pit() = end_pit;
|
|
||||||
d->cursor_.pos() = end_pos;
|
|
||||||
d->cursor_.setSelection();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Cursor & BufferView::cursor()
|
Cursor & BufferView::cursor()
|
||||||
{
|
{
|
||||||
return d->cursor_;
|
return d->cursor_;
|
||||||
|
@ -247,9 +247,6 @@ public:
|
|||||||
void putSelectionAt(DocIterator const & cur,
|
void putSelectionAt(DocIterator const & cur,
|
||||||
int length, bool backwards);
|
int length, bool backwards);
|
||||||
|
|
||||||
/// selects the item at cursor if its paragraph is empty.
|
|
||||||
bool selectIfEmpty(DocIterator & cur);
|
|
||||||
|
|
||||||
/// update the internal \c ViewMetricsInfo.
|
/// update the internal \c ViewMetricsInfo.
|
||||||
void updateMetrics();
|
void updateMetrics();
|
||||||
|
|
||||||
|
@ -1577,7 +1577,7 @@ void GuiDocument::changeNoteFontColor()
|
|||||||
void GuiDocument::deleteNoteFontColor()
|
void GuiDocument::deleteNoteFontColor()
|
||||||
{
|
{
|
||||||
// set the button color back to pref
|
// set the button color back to pref
|
||||||
theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
|
theApp()->getRgbColor(Color_notebg, set_notefontcolor);
|
||||||
colorModule->noteFontColorPB->setStyleSheet(
|
colorModule->noteFontColorPB->setStyleSheet(
|
||||||
colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
|
colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
|
||||||
changed();
|
changed();
|
||||||
|
@ -172,17 +172,11 @@ bool GuiErrorList::goTo(int item)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If this paragraph is empty, highlight the previous one
|
||||||
|
while (dit.paragraph().empty())
|
||||||
|
dit.backwardPos();
|
||||||
|
|
||||||
// Now make the selection.
|
// Now make the selection.
|
||||||
BufferView * bv = const_cast<BufferView *>(bufferview());
|
|
||||||
if (bv->selectIfEmpty(dit)) {
|
|
||||||
// The paragraph is empty but can be selected
|
|
||||||
bv->processUpdateFlags(Update::Force | Update::FitCursor);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (dit.empty()) {
|
|
||||||
// The paragraph is empty and cannot be selected
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// if pos_end is 0, this means it is end-of-paragraph
|
// if pos_end is 0, this means it is end-of-paragraph
|
||||||
pos_type const s = dit.paragraph().size();
|
pos_type const s = dit.paragraph().size();
|
||||||
pos_type const end = err.pos_end ? min(err.pos_end, s) : s;
|
pos_type const end = err.pos_end ? min(err.pos_end, s) : s;
|
||||||
@ -190,6 +184,7 @@ bool GuiErrorList::goTo(int item)
|
|||||||
pos_type const range = end == start ? s - start : end - start;
|
pos_type const range = end == start ? s - start : end - start;
|
||||||
// end-of-paragraph cannot be highlighted, so highlight the last thing
|
// end-of-paragraph cannot be highlighted, so highlight the last thing
|
||||||
dit.pos() = range ? start : end - 1;
|
dit.pos() = range ? start : end - 1;
|
||||||
|
BufferView * bv = const_cast<BufferView *>(bufferview());
|
||||||
// FIXME LFUN
|
// FIXME LFUN
|
||||||
// If we used an LFUN, we would not need these lines:
|
// If we used an LFUN, we would not need these lines:
|
||||||
bv->putSelectionAt(dit, max(range, pos_type(1)), false);
|
bv->putSelectionAt(dit, max(range, pos_type(1)), false);
|
||||||
|
@ -49,10 +49,15 @@ GuiSelectionManager::GuiSelectionManager(
|
|||||||
QPushButton * down,
|
QPushButton * down,
|
||||||
QAbstractListModel * amod,
|
QAbstractListModel * amod,
|
||||||
QAbstractListModel * smod)
|
QAbstractListModel * smod)
|
||||||
: availableLV(avail), selectedLV(sel), addPB(add), deletePB(del),
|
|
||||||
upPB(up), downPB(down), availableModel(amod), selectedModel(smod),
|
|
||||||
selectedHasFocus_(false)
|
|
||||||
{
|
{
|
||||||
|
availableLV = avail;
|
||||||
|
selectedLV = sel;
|
||||||
|
addPB = add;
|
||||||
|
deletePB = del;
|
||||||
|
upPB = up;
|
||||||
|
downPB = down;
|
||||||
|
availableModel = amod;
|
||||||
|
selectedModel = smod;
|
||||||
|
|
||||||
selectedLV->setModel(smod);
|
selectedLV->setModel(smod);
|
||||||
availableLV->setModel(amod);
|
availableLV->setModel(amod);
|
||||||
@ -82,6 +87,7 @@ GuiSelectionManager::GuiSelectionManager(
|
|||||||
|
|
||||||
availableLV->installEventFilter(this);
|
availableLV->installEventFilter(this);
|
||||||
selectedLV->installEventFilter(this);
|
selectedLV->installEventFilter(this);
|
||||||
|
selectedHasFocus_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,34 +140,25 @@ docstring InsetRef::getEscapedLabel(OutputParams const & rp) const
|
|||||||
void InsetRef::latex(otexstream & os, OutputParams const & rp) const
|
void InsetRef::latex(otexstream & os, OutputParams const & rp) const
|
||||||
{
|
{
|
||||||
string const cmd = getCmdName();
|
string const cmd = getCmdName();
|
||||||
|
docstring const data = getEscapedLabel(rp);
|
||||||
|
|
||||||
// refstyle defines its own version of \eqref
|
if (cmd == "eqref" && buffer().params().use_refstyle) {
|
||||||
if (cmd != "formatted" &&
|
os << '(' << from_ascii("\\ref{") << data << from_ascii("})");
|
||||||
!(cmd == "eqref" && buffer().params().use_refstyle)
|
}
|
||||||
) {
|
else if (cmd == "formatted") {
|
||||||
|
docstring label;
|
||||||
|
docstring prefix;
|
||||||
|
docstring const fcmd = getFormattedCmd(data, label, prefix);
|
||||||
|
os << fcmd << '{' << label << '}';
|
||||||
|
}
|
||||||
|
else {
|
||||||
// We don't want to output p_["name"], since that is only used
|
// We don't want to output p_["name"], since that is only used
|
||||||
// in docbook. So we construct new params, without it, and use that.
|
// in docbook. So we construct new params, without it, and use that.
|
||||||
InsetCommandParams p(REF_CODE, cmd);
|
InsetCommandParams p(REF_CODE, cmd);
|
||||||
docstring const ref = getParam("reference");
|
docstring const ref = getParam("reference");
|
||||||
p["reference"] = ref;
|
p["reference"] = ref;
|
||||||
os << p.getCommand(rp);
|
os << p.getCommand(rp);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// so we're doing a formatted reference of some kind.
|
|
||||||
docstring const data = getEscapedLabel(rp);
|
|
||||||
|
|
||||||
// what we say in the UI is that an "eqref" is supposed to surround the
|
|
||||||
// reference with parentheses, so let's do that.
|
|
||||||
if (cmd == "eqref" /* && buffer().params().use_refstyle */) {
|
|
||||||
os << '(' << from_ascii("\\ref{") << data << from_ascii("})");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
docstring label;
|
|
||||||
docstring prefix;
|
|
||||||
docstring const fcmd = getFormattedCmd(data, label, prefix);
|
|
||||||
os << fcmd << '{' << label << '}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user