src: Fix Annotations after Snippet Merge
* snippet::merge does not take code from TextAccess since it could be out of date. Instead it takes the code from the snippets that will be merged.
This commit is contained in:
@@ -87,6 +87,7 @@ QtCodeArea::QtCodeArea(
|
||||
: QPlainTextEdit(parent)
|
||||
, m_fileWidget(file)
|
||||
, m_startLineNumber(startLineNumber)
|
||||
, m_code(code)
|
||||
, m_locationFile(locationFile)
|
||||
, m_digits(0)
|
||||
, m_panningValue(-1)
|
||||
@@ -103,8 +104,8 @@ QtCodeArea::QtCodeArea(
|
||||
m_lineNumberArea = new LineNumberArea(this);
|
||||
m_highlighter = new QtHighlighter(document());
|
||||
|
||||
std::string displayCode = code;
|
||||
if (*code.rbegin() == '\n')
|
||||
std::string displayCode = m_code;
|
||||
if (*displayCode.rbegin() == '\n')
|
||||
{
|
||||
displayCode.pop_back();
|
||||
}
|
||||
@@ -264,6 +265,11 @@ QRectF QtCodeArea::getFirstActiveLineRect() const
|
||||
return blockBoundingGeometry(block);
|
||||
}
|
||||
|
||||
std::string QtCodeArea::getCode() const
|
||||
{
|
||||
return m_code;
|
||||
}
|
||||
|
||||
void QtCodeArea::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
QPlainTextEdit::resizeEvent(e);
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
MouseWheelOverScrollbarFilter(QObject* parent);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject*obj, QEvent* event);
|
||||
bool eventFilter(QObject* obj, QEvent* event);
|
||||
};
|
||||
|
||||
class QtCodeArea
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
: public QWidget
|
||||
{
|
||||
public:
|
||||
LineNumberArea(QtCodeArea *codeArea);
|
||||
LineNumberArea(QtCodeArea* codeArea);
|
||||
virtual ~LineNumberArea();
|
||||
|
||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
virtual void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
QtCodeArea *m_codeArea;
|
||||
QtCodeArea* m_codeArea;
|
||||
};
|
||||
|
||||
static void clearAnnotationColors();
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
|
||||
std::shared_ptr<TokenLocationFile> getTokenLocationFile() const;
|
||||
|
||||
void lineNumberAreaPaintEvent(QPaintEvent *event);
|
||||
void lineNumberAreaPaintEvent(QPaintEvent* event);
|
||||
int lineNumberDigits() const;
|
||||
int lineNumberAreaWidth() const;
|
||||
void updateLineNumberAreaWidthForDigits(int digits);
|
||||
@@ -85,8 +85,10 @@ public:
|
||||
|
||||
QRectF getFirstActiveLineRect() const;
|
||||
|
||||
std::string getCode() const;
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
|
||||
virtual void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
|
||||
virtual void showEvent(QShowEvent* event) Q_DECL_OVERRIDE;
|
||||
virtual void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
|
||||
virtual void enterEvent(QEvent* event) Q_DECL_OVERRIDE;
|
||||
@@ -100,7 +102,7 @@ protected:
|
||||
|
||||
private slots:
|
||||
void updateLineNumberAreaWidth(int newBlockCount);
|
||||
void updateLineNumberArea(const QRect &, int);
|
||||
void updateLineNumberArea(const QRect&, int);
|
||||
void clearSelection();
|
||||
void setIDECursorPosition();
|
||||
|
||||
@@ -160,6 +162,7 @@ private:
|
||||
QtHighlighter* m_highlighter;
|
||||
|
||||
const uint m_startLineNumber;
|
||||
const std::string m_code;
|
||||
|
||||
std::shared_ptr<TokenLocationFile> m_locationFile;
|
||||
|
||||
|
||||
@@ -35,12 +35,15 @@ std::shared_ptr<QtCodeSnippet> QtCodeSnippet::merged(QtCodeSnippet* a, QtCodeSni
|
||||
}
|
||||
);
|
||||
|
||||
std::string code;
|
||||
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(locationFile->getFilePath().str());
|
||||
for (const std::string& line: textAccess->getLines(first->getStartLineNumber(), second->getEndLineNumber()))
|
||||
std::string code = first->getCode();
|
||||
|
||||
std::string secondCode = second->getCode();
|
||||
int secondCodeStartIndex = 0;
|
||||
for (uint i = second->getStartLineNumber(); i <= first->getEndLineNumber(); i++)
|
||||
{
|
||||
code += line;
|
||||
secondCodeStartIndex = secondCode.find("\n", secondCodeStartIndex) + 1;
|
||||
}
|
||||
code += secondCode.substr(secondCodeStartIndex, secondCode.npos);
|
||||
|
||||
std::string title = first->m_titleString;
|
||||
|
||||
@@ -150,6 +153,11 @@ QRectF QtCodeSnippet::getFirstActiveLineRect() const
|
||||
return m_codeArea->getFirstActiveLineRect();
|
||||
}
|
||||
|
||||
std::string QtCodeSnippet::getCode() const
|
||||
{
|
||||
return m_codeArea->getCode();
|
||||
}
|
||||
|
||||
void QtCodeSnippet::contextMenuEvent(QContextMenuEvent* event)
|
||||
{
|
||||
QMenu menu(this);
|
||||
|
||||
@@ -46,6 +46,8 @@ public:
|
||||
|
||||
QRectF getFirstActiveLineRect() const;
|
||||
|
||||
std::string getCode() const;
|
||||
|
||||
protected:
|
||||
virtual void contextMenuEvent(QContextMenuEvent* event) Q_DECL_OVERRIDE;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user