Changeset View
Changeset View
Standalone View
Standalone View
src/vimode/modes/normalvimode.cpp
Show First 20 Lines • Show All 3835 Lines • ▼ Show 20 Line(s) | 3758 | { | |||
---|---|---|---|---|---|
3836 | updateCursor(cursorAfterPaste); | 3836 | updateCursor(cursorAfterPaste); | ||
3837 | 3837 | | |||
3838 | return true; | 3838 | return true; | ||
3839 | } | 3839 | } | ||
3840 | 3840 | | |||
3841 | KTextEditor::Cursor NormalViMode::cursorPosAtEndOfPaste(const KTextEditor::Cursor &pasteLocation, const QString &pastedText) const | 3841 | KTextEditor::Cursor NormalViMode::cursorPosAtEndOfPaste(const KTextEditor::Cursor &pasteLocation, const QString &pastedText) const | ||
3842 | { | 3842 | { | ||
3843 | KTextEditor::Cursor cAfter = pasteLocation; | 3843 | KTextEditor::Cursor cAfter = pasteLocation; | ||
3844 | const auto textLines = pastedText.splitRef(QLatin1Char('\n')); | 3844 | const int lineCount = pastedText.count(QLatin1Char('\n')) + 1; | ||
3845 | if (textLines.length() == 1) { | 3845 | if (lineCount == 1) { | ||
3846 | cAfter.setColumn(cAfter.column() + pastedText.length()); | 3846 | cAfter.setColumn(cAfter.column() + pastedText.length()); | ||
3847 | } else { | 3847 | } else { | ||
3848 | cAfter.setColumn(textLines.last().length() - 0); | 3848 | const int lastLineLength = pastedText.size() - (pastedText.lastIndexOf(QLatin1Char('\n')) + 1); | ||
3849 | cAfter.setLine(cAfter.line() + textLines.length() - 1); | 3849 | cAfter.setColumn(lastLineLength); | ||
3850 | cAfter.setLine(cAfter.line() + lineCount - 1); | ||||
apol: oh I see, how about just using splitRef? This way we don't have to allocate all the strings but… | |||||
Still one allocation done for the vector ;) Not sure about readibility. While the mistake done in formula spoils my point, I find the new code more readable, as the splitref would make me expect more sections are used, while it is just a hack to get the precalculated length of the last section, with info about all other sections discarded. kossebau: Still one allocation done for the vector ;)
Not sure about readibility. While the mistake done… | |||||
3850 | } | 3851 | } | ||
3851 | return cAfter; | 3852 | return cAfter; | ||
3852 | } | 3853 | } | ||
3853 | 3854 | | |||
3854 | void NormalViMode::joinLines(unsigned int from, unsigned int to) const | 3855 | void NormalViMode::joinLines(unsigned int from, unsigned int to) const | ||
3855 | { | 3856 | { | ||
3856 | // make sure we don't try to join lines past the document end | 3857 | // make sure we don't try to join lines past the document end | ||
3857 | if (to >= (unsigned int)(doc()->lines())) { | 3858 | if (to >= (unsigned int)(doc()->lines())) { | ||
▲ Show 20 Lines • Show All 290 Lines • Show Last 20 Lines |
oh I see, how about just using splitRef? This way we don't have to allocate all the strings but the code still is more readable.