mirror of
https://github.com/tnodir/fort
synced 2024-11-15 07:15:39 +00:00
UI: Improve text moving controls.
This commit is contained in:
parent
c810295487
commit
e8b59da409
@ -35,7 +35,14 @@ T.SplitView {
|
||||
|
||||
// Append the text to area
|
||||
const areaOldLen = area.length;
|
||||
area.append(text);
|
||||
const areaOldText = area.text;
|
||||
|
||||
const lineEnd = stringUtil.lineEnd(areaOldText, areaOldLen - 1);
|
||||
if (lineEnd < 0) {
|
||||
area.append(text);
|
||||
} else {
|
||||
area.insert(lineEnd + 1, text);
|
||||
}
|
||||
|
||||
// Select new text
|
||||
selectText(area, areaOldLen, area.length);
|
||||
@ -52,18 +59,31 @@ T.SplitView {
|
||||
}
|
||||
|
||||
function moveSelectedLines(srcArea, dstArea) {
|
||||
//if (!srcArea.has)
|
||||
|
||||
// Cut the text from srcArea
|
||||
const srcText = srcArea.text;
|
||||
const srcStart = stringUtil.lineStart(srcText, srcArea.selectionStart) + 1;
|
||||
const srcEnd = stringUtil.lineEnd(srcText, srcArea.selectionEnd) + 1;
|
||||
const srcTextEnd = srcText.length - 1;
|
||||
|
||||
// Adgust to last line, when cursor at the end
|
||||
if (srcArea.selectionStart === srcArea.selectionEnd
|
||||
&& srcArea.selectionStart > srcTextEnd
|
||||
&& srcTextEnd > 0) {
|
||||
srcArea.cursorPosition = srcTextEnd - 1;
|
||||
}
|
||||
|
||||
const srcSelStart = Math.min(srcArea.selectionStart, srcTextEnd);
|
||||
var srcStart = stringUtil.lineStart(srcText, srcSelStart) + 1;
|
||||
|
||||
const srcSelEnd = srcArea.selectionEnd;
|
||||
const srcEnd = stringUtil.lineEnd(srcText, srcSelEnd, srcTextEnd) + 1;
|
||||
|
||||
if (srcStart >= srcEnd
|
||||
&& --srcStart < 0) // try to select empty line
|
||||
return;
|
||||
|
||||
const text = srcArea.getText(srcStart, srcEnd, srcTextEnd);
|
||||
|
||||
const text = srcArea.getText(srcStart, srcEnd);
|
||||
srcArea.remove(srcStart, srcEnd);
|
||||
srcArea.deselect();
|
||||
|
||||
console.log(">", srcStart, srcEnd, text.length);
|
||||
srcArea.remove(srcStart, srcEnd);
|
||||
|
||||
// Paste the text to dstArea
|
||||
appendText(dstArea, text);
|
||||
@ -129,17 +149,17 @@ T.SplitView {
|
||||
onClicked: moveSelectedLines(textArea1, textArea2)
|
||||
}
|
||||
|
||||
RoundButtonTipSmall {
|
||||
icon.source: "qrc:/images/control_rewind.png"
|
||||
tipText: textMoveAllFrom2To1
|
||||
onClicked: moveAllLines(textArea2, textArea1)
|
||||
}
|
||||
|
||||
RoundButtonTipSmall {
|
||||
icon.source: "qrc:/images/control_play_backward.png"
|
||||
tipText: textMoveSelectedFrom2To1
|
||||
onClicked: moveSelectedLines(textArea2, textArea1)
|
||||
}
|
||||
|
||||
RoundButtonTipSmall {
|
||||
icon.source: "qrc:/images/control_rewind.png"
|
||||
tipText: textMoveAllFrom2To1
|
||||
onClicked: moveAllLines(textArea2, textArea1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,15 @@ QString StringUtil::cryptoHash(const QString &text)
|
||||
return QString::fromLatin1(hash.toHex());
|
||||
}
|
||||
|
||||
int StringUtil::lineStart(const QString &text, int pos)
|
||||
int StringUtil::lineStart(const QString &text, int pos,
|
||||
int badPos)
|
||||
{
|
||||
return text.lastIndexOf(QLatin1Char('\n'), pos);
|
||||
const int startPos = text.lastIndexOf(QLatin1Char('\n'), pos);
|
||||
return (startPos != -1) ? startPos : badPos;
|
||||
}
|
||||
|
||||
int StringUtil::lineEnd(const QString &text, int pos)
|
||||
int StringUtil::lineEnd(const QString &text, int pos, int badPos)
|
||||
{
|
||||
const int end = text.indexOf(QLatin1Char('\n'), pos);
|
||||
return (end > -1) ? end : text.size() - 1;
|
||||
const int endPos = text.indexOf(QLatin1Char('\n'), pos);
|
||||
return (endPos != -1) ? endPos : badPos;
|
||||
}
|
||||
|
@ -14,8 +14,10 @@ public:
|
||||
|
||||
Q_INVOKABLE static QString cryptoHash(const QString &text);
|
||||
|
||||
Q_INVOKABLE static int lineStart(const QString &text, int pos);
|
||||
Q_INVOKABLE static int lineEnd(const QString &text, int pos);
|
||||
Q_INVOKABLE static int lineStart(const QString &text, int pos,
|
||||
int badPos = -1);
|
||||
Q_INVOKABLE static int lineEnd(const QString &text, int pos,
|
||||
int badPos = -1);
|
||||
};
|
||||
|
||||
#endif // STRINGUTIL_H
|
||||
|
Loading…
Reference in New Issue
Block a user