Skip to content

Commit

Permalink
add getTextLength and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
scheffle committed Mar 8, 2024
1 parent a425808 commit 4171acb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vstgui/lib/ctexteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ struct TextEditorView : public CView,

// TextEditorHighlighting::IEditorExt
std::u16string_view readText (size_t startOffset, size_t length) const override;
size_t getTextLength () const override;

// commandos
bool doShifting (bool right) const;
Expand Down Expand Up @@ -867,6 +868,9 @@ std::u16string_view TextEditorView::readText (size_t startOffset, size_t length)
return {md.model.text.data () + startOffset, length};
}

//------------------------------------------------------------------------
size_t TextEditorView::getTextLength () const { return md.model.text.length (); }

//------------------------------------------------------------------------
inline Range toLineSelection (const Range& line, size_t selStart, size_t selEnd)
{
Expand Down
29 changes: 29 additions & 0 deletions vstgui/lib/ctexteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,18 @@ namespace TextEditorColorization {
/** extension to ITextEditor, use a dynamic_cast to get it from an ITextEditor */
struct IEditorExt
{
/** get access to the internal string buffer of the text editor
*
* @param startOffset offset into the buffer in number of characters
* @param length number of characters
* @return a string view into the buffer
*/
virtual std::u16string_view readText (size_t startOffset, size_t length) const = 0;
/** get the length of the text
*
* @return number of characters
*/
virtual size_t getTextLength () const = 0;
};

//------------------------------------------------------------------------
Expand All @@ -132,8 +143,26 @@ struct IStyleProvider
};
using Styles = std::vector<Style>;

/** notification that drawing begins
*
* @param editor reference to the editor
*/
virtual void beginDraw (const IEditorExt& editor) = 0;
/** get the styles of the text
*
* The returned styles must be orded from front to back.
* If ranges are missing in the styles, they are rendered with the default style.
*
* @param editor reference to the editor
* @param beginOffset offset into the text buffer in number of characters
* @param length number of characters
* @return vector of styles for the range
*/
virtual Styles getStyles (const IEditorExt& editor, size_t beginOffset, size_t length) = 0;
/** notification that drawing has ended
*
* @param editor reference to the editor
*/
virtual void endDraw (const IEditorExt& editor) = 0;
};

Expand Down

0 comments on commit 4171acb

Please sign in to comment.