Skip to content

Commit f14c146

Browse files
committed
ref edbee#134, textChange signals with oldText
- add oldText info to textChange signals (possible breaking change of some interfaces) - fix undo crash by missing oldText in AccessibleTextEditorWidget::notifyTextSelectionEvent - add some extra range checks. OS X voice-over, somethimes asks text out of range. With a length of -1 or outside document length
1 parent c4c9ad7 commit f14c146

15 files changed

Lines changed: 50 additions & 36 deletions

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
## Upcoming Release
1+
# Upcoming Release
22

33
edbee.lib:
44

5+
- add #135, QAccessibleTextInterface support
6+
- add TextBuffer::emitTextChanged is extended with the oldText. SIGNAL void emitTextChanged( TextBufferChange* change, QString oldText = QString()); (WARNING: signal interface changes )
57
- fix #133, Added Qt 6.3.0 compatibility
68
- fix #132, Writing diacritics in Linux
79
- ref #128, Build in supprort for virtual characters. Alternate position/cursor calculations via TextLayout

edbee-lib/edbee/models/chardocument/chartextbuffer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,16 @@ void CharTextBuffer::replaceText(int offset, int length, const QChar* buffer, in
8383
emit textAboutToBeChanged( change );
8484

8585
// replace the text
86+
QString oldText = buf_.mid(offset, length);
87+
8688
buf_.replace( offset, length, buffer, bufferLength );
8789

8890
// replace the line data and offsets
8991
lineOffsetList_.applyChange( change );
9092

9193
// emit linesReplaced( change.line, change.lineCount, change.newLineCount );
9294
// emit textReplaced( offset, length, buffer, bufferLength );
93-
emit textChanged( change );
95+
emit textChanged( change, oldText );
9496

9597
}
9698

@@ -168,7 +170,7 @@ void CharTextBuffer::rawAppendEnd()
168170

169171
emit textAboutToBeChanged( change );
170172
lineOffsetList_.applyChange( change );
171-
emit textChanged( change );
173+
emit textChanged( change, QString() );
172174

173175
rawAppendLineStart_ = -1;
174176
rawAppendStart_ = -1;

edbee-lib/edbee/models/chardocument/chartextbuffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class EDBEE_EXPORT CharTextBuffer : public TextBuffer
4343

4444
protected slots:
4545

46-
void emitTextChanged( edbee::TextBufferChange* change );
46+
void emitTextChanged( edbee::TextBufferChange* change, QString oldText = QString());
4747

4848
private:
4949
QCharGapVector buf_; ///< The textbuffer

edbee-lib/edbee/models/chardocument/chartextdocument.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ CharTextDocument::CharTextDocument(QObject *object)
5959

6060
// simply forward the about to change signal
6161
connect( textBuffer_, SIGNAL(textAboutToBeChanged(edbee::TextBufferChange)), SIGNAL(textAboutToBeChanged(edbee::TextBufferChange)), Qt::DirectConnection );
62-
connect( textBuffer_, SIGNAL(textChanged(edbee::TextBufferChange)), SLOT(textBufferChanged(edbee::TextBufferChange)), Qt::DirectConnection );
62+
connect( textBuffer_, SIGNAL(textChanged(edbee::TextBufferChange, QString)), SLOT(textBufferChanged(edbee::TextBufferChange, QString)), Qt::DirectConnection );
6363

6464
// forward the persisted state changes
6565
connect( textUndoStack_, SIGNAL(persistedChanged(bool)), this, SIGNAL(persistedChanged(bool)) );
@@ -143,7 +143,7 @@ Change *CharTextDocument::giveChangeWithoutFilter(Change *change, int coalesceId
143143

144144

145145
// the text is changed
146-
void CharTextDocument::textBufferChanged(const TextBufferChange& change)
146+
void CharTextDocument::textBufferChanged(const TextBufferChange& change, QString oldText)
147147
{
148148
if( textLexer_ ) {
149149
textLexer_->textChanged( change );
@@ -158,7 +158,7 @@ void CharTextDocument::textBufferChanged(const TextBufferChange& change)
158158
}
159159

160160
// emit the textchanged singal
161-
emit textChanged( change); // and notify the document listeners
161+
emit textChanged(change, oldText); // and notify the document listeners
162162
}
163163

164164

edbee-lib/edbee/models/chardocument/chartextdocument.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Q_OBJECT
7979
protected slots:
8080
// virtual void textReplaced( int offset, int length, const QChar* data, int dataLength );
8181
// virtual void linesReplaced( int line, int lineCount, int newLineCount );
82-
virtual void textBufferChanged( const edbee::TextBufferChange& change );
82+
virtual void textBufferChanged( const edbee::TextBufferChange& change, QString oldText = QString() );
8383

8484
private:
8585
TextEditorConfig* config_; ///< The text editor configuration

edbee-lib/edbee/models/textbuffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Q_OBJECT
145145
signals:
146146

147147
void textAboutToBeChanged( edbee::TextBufferChange change );
148-
void textChanged( edbee::TextBufferChange change );
148+
void textChanged( edbee::TextBufferChange change, QString oldText = QString() );
149149

150150
};
151151

edbee-lib/edbee/models/textdocument.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Q_OBJECT
157157
signals:
158158

159159
void textAboutToBeChanged( edbee::TextBufferChange change );
160-
void textChanged( edbee::TextBufferChange change );
160+
void textChanged( edbee::TextBufferChange change, QString oldText = QString() );
161161

162162
/// This signal is emitted if the persisted state is changed
163163
void persistedChanged(bool persisted);

edbee-lib/edbee/models/textrange.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ bool DynamicTextRangeSet::deleteMode() const
12301230

12311231

12321232
/// This method is notified if a change happens to the textbuffer
1233-
void DynamicTextRangeSet::textChanged(edbee::TextBufferChange change)
1233+
void DynamicTextRangeSet::textChanged(edbee::TextBufferChange change, QString oldText)
12341234
{
12351235
changeSpatial( change.offset(), change.length(), change.newTextLength(), stickyMode_, deleteMode_ );
12361236
}

edbee-lib/edbee/models/textrange.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ Q_OBJECT
256256
bool deleteMode() const;
257257

258258
public slots:
259-
void textChanged( edbee::TextBufferChange change );
259+
void textChanged( edbee::TextBufferChange change, QString oldText = QString() );
260260

261261
private:
262262
bool stickyMode_; ///< Sticky mode means if this rangeset is the current selection (This requires a different approach)

edbee-lib/edbee/texteditorcontroller.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void TextEditorController::setTextDocument(TextDocument* doc)
131131
TextDocument* oldDocumentRef = textDocument();
132132
if( oldDocumentRef ) {
133133
oldDocumentRef->textUndoStack()->unregisterController(this);
134-
disconnect( oldDocumentRef, SIGNAL(textChanged(edbee::TextBufferChange)), this, SLOT(onTextChanged(edbee::TextBufferChange)) );
134+
disconnect( oldDocumentRef, SIGNAL(textChanged(edbee::TextBufferChange, QString)), this, SLOT(onTextChanged(edbee::TextBufferChange, QString)) );
135135
disconnect( textDocumentRef_->lineDataManager(), SIGNAL(lineDataChanged(int,int,int)), this, SLOT(onLineDataChanged(int,int,int)));
136136
}
137137

@@ -151,7 +151,7 @@ void TextEditorController::setTextDocument(TextDocument* doc)
151151

152152
textDocumentRef_->textUndoStack()->registerContoller(this);
153153

154-
connect( textDocumentRef_, SIGNAL(textChanged(edbee::TextBufferChange)), this, SLOT(onTextChanged(edbee::TextBufferChange)));
154+
connect( textDocumentRef_, SIGNAL(textChanged(edbee::TextBufferChange, QString)), this, SLOT(onTextChanged(edbee::TextBufferChange, QString)));
155155
connect( textDocumentRef_->lineDataManager(), SIGNAL(lineDataChanged(int,int,int)), this, SLOT(onLineDataChanged(int,int,int)) );
156156

157157
// force an repaint when the grammar is changed
@@ -366,10 +366,8 @@ DynamicVariables* TextEditorController::dynamicVariables() const
366366

367367

368368
/// This slot is placed if a piece of text is replaced
369-
void TextEditorController::onTextChanged( edbee::TextBufferChange change )
369+
void TextEditorController::onTextChanged( edbee::TextBufferChange change, QString oldText )
370370
{
371-
Q_UNUSED(change)
372-
373371
/// update the selection
374372
// textSelection()->changeSpatial( change.offset(), change.length(), change.newTextLength() );
375373

@@ -378,7 +376,7 @@ void TextEditorController::onTextChanged( edbee::TextBufferChange change )
378376
widget()->updateGeometryComponents();
379377
notifyStateChange();
380378

381-
AccessibleTextEditorWidget::notifyTextChangeEvent(widget(), &change);
379+
AccessibleTextEditorWidget::notifyTextChangeEvent(widget(), &change, oldText);
382380
}
383381
}
384382

0 commit comments

Comments
 (0)