TSynEdit
| Component | Description |
|---|---|
![]() | TSynEdit is the syntax highlighting editor. It paints the text by itself (it is not a Windows common control) and is the base of the whole library: highlighters, completion, search, printing, spell check and the other components all work on a TSynEdit. |
Unit: SynEdit.Core. Inheritance: TCustomControl > TCustomSynEdit > TSynEdit. Platforms: Win32 and Win64.
uses
SynEdit.Core, SynEdit.Highlighter.Pas;Main features
- Syntax highlighting with any of the 63 highlighters, assigned with the
Highlighterproperty. - Gutter with line numbers, bookmarks and your own custom bands (see the Simple IDE demo).
- Code folding (
UseCodeFolding,CodeFolding). - Word wrap (
WordWrap,WordWrapGlyph), indent guides, visible special characters (VisibleSpecialChars), right edge, active line color and bracket highlighting. - Multiple carets and selection modes, triple and quadruple click, drag and drop editing.
- Undo and redo with grouping (
eoGroupUndo,MaxUndo). - Bookmarks (
BookmarkOptions,OnPlaceBookmark,OnClearBookmark). - Rendering with Direct2D/DirectWrite, ClearType and optional font ligatures (
eoShowLigatures). - Accessibility support (
eoAccessibility). - Zoom with the mouse wheel (
OnZoom). - Scroll bar annotations (
ScrollbarAnnotations) to show search results and marks on the scroll bar. - Customizable keystrokes (
Keystrokes) mapped to editor commands (ecXxx).
Most used properties
| Property | Description |
|---|---|
Lines | The text, as a TStrings: Lines.LoadFromFile, Lines.Text... |
Highlighter | The highlighter used to color the text. |
Options | Set of TSynEditorOption flags (see below). |
ScrollOptions | Set of TSynEditorScrollOption flags. |
Gutter | Appearance of the gutter: width, line numbers, bands. |
UseCodeFolding, CodeFolding | Enable and configure code folding. |
SearchEngine | The engine used by SearchReplace: see Search and Replace. |
TabWidth, RightEdge, RightEdgeColor | Tab size and the vertical line at a given column. |
WordWrap, WordWrapGlyph | Soft wrap of the long lines. |
ActiveLineColor, SelectedColor | Colors of the active line and of the selection. |
ReadOnly, InsertMode, HideSelection | Behavior of the editor. |
Keystrokes | The key bindings. |
FontQuality | Font rendering quality (default fqClearTypeNatural). |
TextHint | Placeholder shown when the editor is empty. |
Editor options
The Options property is a set of TSynEditorOption. The default is:
eoAutoIndent, eoDragDropEditing, eoKeepCaretX, eoEnhanceHomeKey, eoEnhanceEndKey, eoTabIndent, eoTabsToSpaces, eoSmartTabDelete, eoGroupUndo, eoDropFiles, eoShowLigatures, eoBracketsHighlight, eoAccessibility, eoCompleteBrackets, eoCompleteQuotes.
| Option | Effect |
|---|---|
eoAutoIndent | A new line gets the same indentation of the previous one. |
eoDragDropEditing | Selected text can be dragged to another position. |
eoDropFiles | The editor accepts files dropped from the Explorer (OnDropFiles). |
eoEnhanceHomeKey, eoEnhanceEndKey | Smarter Home and End keys. |
eoGroupUndo | Undo and redo handle together the continuous changes of the same kind. |
eoKeepCaretX | Keeps the X position of the caret when moving between lines. |
eoSmartTabs, eoSmartTabDelete | The tab goes to the next non-blank character of the previous line. |
eoTabIndent | Tab and Shift+Tab indent and unindent the selected block. |
eoTabsToSpaces | Tabs are converted to spaces. |
eoTrimTrailingSpaces | Trailing spaces are removed. |
eoShowLigatures | Shows the ligatures of the font. |
eoBracketsHighlight | Highlights the matching bracket. |
eoCompleteBrackets, eoCompleteQuotes | Adds the closing bracket or quote while typing. |
eoCopyPlainText | The clipboard receives only plain text. |
eoNoCaret, eoNoSelection | No caret or no selection (viewers). |
eoWrapWithRightEdge | The word wrap uses the right edge position. |
eoAccessibility | Enables the accessibility support. |
The scroll options (ScrollOptions) include eoHideShowScrollbars, eoDisableScrollArrows, eoShowScrollHint, eoScrollPastEof, eoScrollPastEol, eoHalfPageScroll, eoScrollByOneLess and eoScrollHintFollows.
Example
procedure TForm1.FormCreate(Sender: TObject);
begin
SynEdit1.Highlighter := SynPasSyn1;
SynEdit1.Options := SynEdit1.Options + [eoTrimTrailingSpaces];
SynEdit1.UseCodeFolding := True;
SynEdit1.Lines.LoadFromFile('Unit1.pas');
end;Useful methods
| Method | Description |
|---|---|
SearchReplace(ASearch, AReplace, AOptions) | Searches and replaces text, returns the number of matches (see Search and Replace). |
ExecuteCommand(Command, AChar, Data) | Executes an editor command (ecXxx) as if the key was pressed. |
GetWordAtRowCol(XY) | The word at a given position. |
GotoLineAndCenter(ALine) | Moves the caret to a line and centers it. |
SelectAll, SelectAllMatchingText | Selection. |
CopyToClipboard, CutToClipboard, PasteFromClipboard | Clipboard. |
Undo, Redo, ClearAll | History and content. |
BeginUpdate, EndUpdate | Suspend and resume the painting while changing the text (IncPaintLock and DecPaintLock are aliases kept for backward compatibility). |
CollapseAll | Collapses all the foldable blocks. |
AddKey(Command, Key1, SS1, ...) | Adds a key binding. |
Main events
OnChange, OnStatusChange, OnProcessCommand, OnCommandProcessed, OnProcessUserCommand, OnGutterClick, OnGutterGetText, OnSpecialLineColors, OnPaint, OnPaintTransient, OnReplaceText, OnSearchNotFound, OnPlaceBookmark, OnClearBookmark, OnDropFiles, OnScanForFoldRanges, OnZoom, OnTripleClick, OnQuadrupleClick, OnMouseCursor and OnScroll.
Compatibility properties
FontSmoothing (with the type TSynFontSmoothMethod) is kept for the DFMs written with the older versions of SynEdit: the font quality is defined by FontQuality.

