@@ -45,6 +45,7 @@ CodeEditor::CodeEditor(QWidget *parent, bool withBeakpoints) :
4545 breakpointImage(" :/images/breakpoint.png" )
4646{
4747 hasBreakpoints = withBeakpoints;
48+ prevBlockCount = -1 ;
4849 this ->setDebugMode (false );
4950 debugAreaWidth = 3 + debugImage.width () + 1 ;
5051 this ->setWordWrapMode (QTextOption::NoWrap);
@@ -54,6 +55,7 @@ CodeEditor::CodeEditor(QWidget *parent, bool withBeakpoints) :
5455 connect (this , SIGNAL (blockCountChanged (int )), this , SLOT (updateLineNumberAreaWidth (int )));
5556 connect (this , SIGNAL (updateRequest (QRect,int )), this , SLOT (updateLineNumberArea (QRect,int )));
5657 connect (this , SIGNAL (cursorPositionChanged ()), this , SLOT (highlightCurrentLine ()));
58+ connect (this , SIGNAL (blockCountChanged (int )), this , SLOT (shiftBreakpoints (int )));
5759
5860 updateLineNumberAreaWidth (0 );
5961 highlightCurrentLine ();
@@ -101,14 +103,6 @@ void CodeEditor::resizeEvent(QResizeEvent *e)
101103
102104void CodeEditor::lineNumberAreaPaintEvent (QPaintEvent *event)
103105{
104- // delete invisible breakpoints
105- QMutableListIterator<int > i (breakpoints);
106- while (i.hasNext ()) {
107- int num = i.next ();
108- if (num > this ->document ()->blockCount ())
109- i.remove ();
110- }
111-
112106 // paint on line number area
113107 QPainter painter (lineNumberArea);
114108 painter.fillRect (event->rect (), QColor (240 , 240 , 240 ));
@@ -298,7 +292,7 @@ void CodeEditor::deleteTab()
298292
299293void CodeEditor::keyPressEvent (QKeyEvent *e)
300294{
301- QString curString = this -> textCursor ().block ().text ();
295+ QString curString = textCursor ().block ().text ();
302296 int indentWidth = -1 ;
303297 switch (e->key ()) {
304298 case (Qt::Key_Tab) :
@@ -331,6 +325,36 @@ void CodeEditor::keyPressEvent(QKeyEvent *e)
331325 }
332326}
333327
328+ void CodeEditor::shiftBreakpoints (int blockCount)
329+ {
330+ if (prevBlockCount == -1 ) {
331+ prevBlockCount = this ->blockCount ();
332+ return ;
333+ }
334+ // remove breakpoints in range
335+ int changedLine = textCursor ().blockNumber () + 1 ; // blocks starts from 0
336+ if (blockCount < prevBlockCount) {
337+ for (int i = changedLine + 1 ; i <= changedLine + prevBlockCount - blockCount; i++) {
338+ breakpoints.removeOne (i);
339+ }
340+ }
341+
342+ // shift breakpoints
343+ if (blockCount > prevBlockCount) {
344+ for (int i = 0 ; i < breakpoints.size (); i++) {
345+ if (breakpoints[i] >= changedLine)
346+ breakpoints[i] += blockCount - prevBlockCount;
347+ }
348+ } else {
349+ for (int i = 0 ; i < breakpoints.size (); i++) {
350+ if (breakpoints[i] > changedLine)
351+ breakpoints[i] += blockCount - prevBlockCount;
352+ }
353+ }
354+ prevBlockCount = blockCount;
355+ repaintLineNumberArea ();
356+ }
357+
334358CodeEditor::~CodeEditor ()
335359{
336360 delete lineNumberArea;
0 commit comments