mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-19 01:04:20 +00:00
Changed the callback methods used by CodeDocument::Listener, to provide more detail about the exact changes.
This commit is contained in:
parent
ec995d9753
commit
de916db567
4 changed files with 51 additions and 28 deletions
|
|
@ -549,12 +549,22 @@ int CodeDocument::getMaximumLineLength() noexcept
|
|||
|
||||
void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
|
||||
{
|
||||
remove (startPosition.getPosition(), endPosition.getPosition(), true);
|
||||
deleteSection (startPosition.getPosition(), endPosition.getPosition());
|
||||
}
|
||||
|
||||
void CodeDocument::deleteSection (int start, int end)
|
||||
{
|
||||
remove (start, end, true);
|
||||
}
|
||||
|
||||
void CodeDocument::insertText (const Position& position, const String& text)
|
||||
{
|
||||
insert (text, position.getPosition(), true);
|
||||
insertText (position.getPosition(), text);
|
||||
}
|
||||
|
||||
void CodeDocument::insertText (int insertIndex, const String& text)
|
||||
{
|
||||
insert (text, insertIndex, true);
|
||||
}
|
||||
|
||||
void CodeDocument::replaceAllContent (const String& newContent)
|
||||
|
|
@ -633,7 +643,7 @@ namespace CodeDocumentHelpers
|
|||
}
|
||||
}
|
||||
|
||||
const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const noexcept
|
||||
CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const noexcept
|
||||
{
|
||||
Position p (position);
|
||||
const int maxDistance = 256;
|
||||
|
|
@ -671,7 +681,7 @@ const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& p
|
|||
return p;
|
||||
}
|
||||
|
||||
const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const noexcept
|
||||
CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const noexcept
|
||||
{
|
||||
Position p (position);
|
||||
const int maxDistance = 256;
|
||||
|
|
@ -734,14 +744,6 @@ void CodeDocument::checkLastLineStatus()
|
|||
void CodeDocument::addListener (CodeDocument::Listener* const l) noexcept { listeners.add (l); }
|
||||
void CodeDocument::removeListener (CodeDocument::Listener* const l) noexcept { listeners.remove (l); }
|
||||
|
||||
void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
|
||||
{
|
||||
Position startPos (*this, startLine, 0);
|
||||
Position endPos (*this, endLine, 0);
|
||||
|
||||
listeners.call (&CodeDocument::Listener::codeDocumentChanged, startPos, endPos);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
class CodeDocumentInsertAction : public UndoableAction
|
||||
{
|
||||
|
|
@ -834,7 +836,7 @@ void CodeDocument::insert (const String& text, const int insertPos, const bool u
|
|||
p.setPosition (p.getPosition() + newTextLength);
|
||||
}
|
||||
|
||||
sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
|
||||
listeners.call (&CodeDocument::Listener::codeDocumentTextInserted, text, insertPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -936,6 +938,6 @@ void CodeDocument::remove (const int startPos, const int endPos, const bool undo
|
|||
p.setPosition (totalChars);
|
||||
}
|
||||
|
||||
sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
|
||||
listeners.call (&CodeDocument::Listener::codeDocumentTextDeleted, startPos, endPos);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -178,7 +178,6 @@ public:
|
|||
*/
|
||||
String getLineText() const;
|
||||
|
||||
//==============================================================================
|
||||
private:
|
||||
CodeDocument* owner;
|
||||
int characterPos, line, indexInLine;
|
||||
|
|
@ -205,17 +204,25 @@ public:
|
|||
int getMaximumLineLength() noexcept;
|
||||
|
||||
/** Deletes a section of the text.
|
||||
|
||||
This operation is undoable.
|
||||
*/
|
||||
void deleteSection (const Position& startPosition, const Position& endPosition);
|
||||
|
||||
/** Inserts some text into the document at a given position.
|
||||
/** Deletes a section of the text.
|
||||
This operation is undoable.
|
||||
*/
|
||||
void deleteSection (int startIndex, int endIndex);
|
||||
|
||||
/** Inserts some text into the document at a given position.
|
||||
This operation is undoable.
|
||||
*/
|
||||
void insertText (const Position& position, const String& text);
|
||||
|
||||
/** Inserts some text into the document at a given position.
|
||||
This operation is undoable.
|
||||
*/
|
||||
void insertText (int insertIndex, const String& text);
|
||||
|
||||
/** Clears the document and replaces it with some new text.
|
||||
|
||||
This operation is undoable - if you're trying to completely reset the document, you
|
||||
|
|
@ -292,10 +299,10 @@ public:
|
|||
|
||||
//==============================================================================
|
||||
/** Searches for a word-break. */
|
||||
const Position findWordBreakAfter (const Position& position) const noexcept;
|
||||
Position findWordBreakAfter (const Position& position) const noexcept;
|
||||
|
||||
/** Searches for a word-break. */
|
||||
const Position findWordBreakBefore (const Position& position) const noexcept;
|
||||
Position findWordBreakBefore (const Position& position) const noexcept;
|
||||
|
||||
//==============================================================================
|
||||
/** An object that receives callbacks from the CodeDocument when its text changes.
|
||||
|
|
@ -307,10 +314,11 @@ public:
|
|||
Listener() {}
|
||||
virtual ~Listener() {}
|
||||
|
||||
/** Called by a CodeDocument when it is altered.
|
||||
*/
|
||||
virtual void codeDocumentChanged (const Position& affectedTextStart,
|
||||
const Position& affectedTextEnd) = 0;
|
||||
/** Called by a CodeDocument when text is added. */
|
||||
virtual void codeDocumentTextInserted (const String& newText, int insertIndex) = 0;
|
||||
|
||||
/** Called by a CodeDocument when text is deleted. */
|
||||
virtual void codeDocumentTextDeleted (int startIndex, int endIndex) = 0;
|
||||
};
|
||||
|
||||
/** Registers a listener object to receive callbacks when the document changes.
|
||||
|
|
@ -387,8 +395,6 @@ private:
|
|||
ListenerList <Listener> listeners;
|
||||
String newLineChars;
|
||||
|
||||
void sendListenerChangeMessage (int startLine, int endLine);
|
||||
|
||||
void insert (const String& text, int insertPos, bool undoable);
|
||||
void remove (int startPos, int endPos, bool undoable);
|
||||
void checkLastLineStatus();
|
||||
|
|
|
|||
|
|
@ -410,9 +410,21 @@ void CodeEditorComponent::setLineNumbersShown (const bool shouldBeShown)
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
|
||||
const CodeDocument::Position& affectedTextEnd)
|
||||
void CodeEditorComponent::codeDocumentTextInserted (const String& newText, int insertIndex)
|
||||
{
|
||||
codeDocumentChanged (insertIndex, insertIndex + newText.length());
|
||||
}
|
||||
|
||||
void CodeEditorComponent::codeDocumentTextDeleted (int startIndex, int endIndex)
|
||||
{
|
||||
codeDocumentChanged (startIndex, endIndex);
|
||||
}
|
||||
|
||||
void CodeEditorComponent::codeDocumentChanged (const int startIndex, const int endIndex)
|
||||
{
|
||||
const CodeDocument::Position affectedTextStart (document, startIndex);
|
||||
const CodeDocument::Position affectedTextEnd (document, endIndex);
|
||||
|
||||
clearCachedIterators (affectedTextStart.getLineNumber());
|
||||
|
||||
triggerAsyncUpdate();
|
||||
|
|
|
|||
|
|
@ -375,7 +375,10 @@ private:
|
|||
void timerCallback();
|
||||
void scrollBarMoved (ScrollBar*, double);
|
||||
void handleAsyncUpdate();
|
||||
void codeDocumentChanged (const CodeDocument::Position&, const CodeDocument::Position&);
|
||||
|
||||
void codeDocumentTextInserted (const String& newText, int insertIndex);
|
||||
void codeDocumentTextDeleted (int startIndex, int endIndex);
|
||||
void codeDocumentChanged (int startIndex, int endIndex);
|
||||
|
||||
void moveLineDelta (int delta, bool selecting);
|
||||
int getGutterSize() const noexcept;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue