From f59d67e5f037fb53f3395a9219e2ef98f068dc9f Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Mon, 20 Sep 2021 23:33:53 +0800 Subject: [PATCH] work save --- RedPandaIDE/qsynedit/SynEdit.cpp | 24 ++++++++++++++++++++++++ RedPandaIDE/qsynedit/SynEdit.h | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 12c3b44c..4e8da1ab 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -783,6 +783,30 @@ QChar SynEdit::charAtNormalizedBufferPos(const NormalizedBufferCoord &p) const return s[p.Char-1]; } +QStringList SynEdit::getContents(const NormalizedBufferCoord &pStart, const NormalizedBufferCoord &pEnd) +{ + QStringList result; + if (mLines->count()==0) + return result; + if (pStart.Line>0) { + QString s = mLines->getString(pStart.Line-1); + result += s.mid(pStart.Char-1); + } + int endLine = std::min(pEnd.Line,mLines->count()); + for (int i=pStart.Line;igetString(i); + } + if (pEnd.Line<=mLines->count()) { + result += mLines->getString(pEnd.Line-1).mid(0,pEnd.Char-1); + } + return result; +} + +QString SynEdit::getJoinedContents(const NormalizedBufferCoord &pStart, const NormalizedBufferCoord &pEnd, const QString &joinStr) +{ + return getContents(pStart,pEnd).join(joinStr); +} + int SynEdit::leftSpaces(const QString &line) const { int result = 0; diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index 8f0b0430..3a3b3f11 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -166,12 +166,14 @@ public: DisplayCoord bufferToDisplayPos(const BufferCoord& p) const; BufferCoord displayToBufferPos(const DisplayCoord& p) const; - + //normalized buffer coord operations NormalizedBufferCoord moveBufferPos(const BufferCoord&p, int delta) const; NormalizedBufferCoord moveBufferPos(const NormalizedBufferCoord &p, int delta) const; NormalizedBufferCoord normalizeBufferPos(const BufferCoord& p) const; NormalizedBufferCoord normalizeBufferPos(int aChar, int aLine) const; QChar charAtNormalizedBufferPos(const NormalizedBufferCoord& p) const; + QStringList getContents(const NormalizedBufferCoord& pStart,const NormalizedBufferCoord& pEnd); + QString getJoinedContents(const NormalizedBufferCoord& pStart,const NormalizedBufferCoord& pEnd, const QString& joinStr); int leftSpaces(const QString& line) const; QString GetLeftSpacing(int charCount,bool wantTabs) const;