Skip to content

TSynEdit ​

ComponentDescription
SynEditTSynEdit 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.

pascal
uses
  SynEdit.Core, SynEdit.Highlighter.Pas;

Main features ​

  • Syntax highlighting with any of the 63 highlighters, assigned with the Highlighter property.
  • 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 ​

PropertyDescription
LinesThe text, as a TStrings: Lines.LoadFromFile, Lines.Text...
HighlighterThe highlighter used to color the text.
OptionsSet of TSynEditorOption flags (see below).
ScrollOptionsSet of TSynEditorScrollOption flags.
GutterAppearance of the gutter: width, line numbers, bands.
UseCodeFolding, CodeFoldingEnable and configure code folding.
SearchEngineThe engine used by SearchReplace: see Search and Replace.
TabWidth, RightEdge, RightEdgeColorTab size and the vertical line at a given column.
WordWrap, WordWrapGlyphSoft wrap of the long lines.
ActiveLineColor, SelectedColorColors of the active line and of the selection.
ReadOnly, InsertMode, HideSelectionBehavior of the editor.
KeystrokesThe key bindings.
FontQualityFont rendering quality (default fqClearTypeNatural).
TextHintPlaceholder 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.

OptionEffect
eoAutoIndentA new line gets the same indentation of the previous one.
eoDragDropEditingSelected text can be dragged to another position.
eoDropFilesThe editor accepts files dropped from the Explorer (OnDropFiles).
eoEnhanceHomeKey, eoEnhanceEndKeySmarter Home and End keys.
eoGroupUndoUndo and redo handle together the continuous changes of the same kind.
eoKeepCaretXKeeps the X position of the caret when moving between lines.
eoSmartTabs, eoSmartTabDeleteThe tab goes to the next non-blank character of the previous line.
eoTabIndentTab and Shift+Tab indent and unindent the selected block.
eoTabsToSpacesTabs are converted to spaces.
eoTrimTrailingSpacesTrailing spaces are removed.
eoShowLigaturesShows the ligatures of the font.
eoBracketsHighlightHighlights the matching bracket.
eoCompleteBrackets, eoCompleteQuotesAdds the closing bracket or quote while typing.
eoCopyPlainTextThe clipboard receives only plain text.
eoNoCaret, eoNoSelectionNo caret or no selection (viewers).
eoWrapWithRightEdgeThe word wrap uses the right edge position.
eoAccessibilityEnables the accessibility support.

The scroll options (ScrollOptions) include eoHideShowScrollbars, eoDisableScrollArrows, eoShowScrollHint, eoScrollPastEof, eoScrollPastEol, eoHalfPageScroll, eoScrollByOneLess and eoScrollHintFollows.

Example ​

pascal
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 ​

MethodDescription
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, SelectAllMatchingTextSelection.
CopyToClipboard, CutToClipboard, PasteFromClipboardClipboard.
Undo, Redo, ClearAllHistory and content.
BeginUpdate, EndUpdateSuspend and resume the painting while changing the text (IncPaintLock and DecPaintLock are aliases kept for backward compatibility).
CollapseAllCollapses 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.

Released under the MPL 1.1 / GPL 2 dual license.