Forum > SynEdit

A few questions about SynEdit.

(1/2) > >>

CM630:
I tried to use TSynEdit, etc.
I have a few questions/problems:

1. By default TSynEdit is a multiline control. Does it have a genuine ability to switch single line only mode?
2. By default the Delete and the Backspace keys do not work properly. Delete shall erase one character forth, backspace shall erase one character back. But each of them shall erase the selection.
This is not happening.
Their actions are defined in the Keystrokes property of TSynEdit, but I cannot find how to define both (conditional) actions per key.

Edit: Maybe the answer is here: https://wiki.lazarus.freepascal.org/SynEdit#Adding_hotkeys_for_Cut.2FCopy.2FPaste.2Fetc, I will try it.

3. For some reason after an item is selected from the popup of a TSynCompeltion the Activate event of the main form is triggered. Is this the expected behaviour?
4. When I click with the mouse on an area after the last character of the line, the cursor goes there. Is the an option to limit the right (or left in LTF languages) position of the cursor to the rightmost character (like shown on the screenshot)?
5. Any guide / info about using a spellchecker with SynEdit is welcome. Shall I create a custom highlighter?

rvk:

--- Quote from: CM630 on February 19, 2024, 01:34:01 pm ---1. By default TEdit is a multiline control. Does it have a genuine ability to switch single line only mode?
--- End quote ---
Did you mean TSynEdit? TEdit should be single line by default.


--- Quote from: CM630 on February 19, 2024, 01:34:01 pm ---2. By default the Delete and the Backspace keys do not work properly. Delete shall erase one character forth, backspace shall erase one character back. But each of them shall erase the selection.
--- End quote ---
Works fine for me in TSynEdit (on Windows).


--- Quote from: CM630 on February 19, 2024, 01:34:01 pm ---4. When I click with the mouse on an area after the last character of the line, the cursor goes there.
--- End quote ---
Yes, this is default in TSynEdit.
You can exclude TSynEdit.Option the option eoScrollPastEol (and possibly eoScrollPastEof).


--- Quote from: CM630 on February 19, 2024, 01:34:01 pm ---5. Any guide / info about using a spellchecker with SynEdit is welcome. Shall I create a custom highlighter?

--- End quote ---
You could. The simplest method would be a combination of LazSpell with the TSynEdit.OnPaint and drawing on TSynEdit.Canvas.
But creating a proper highlighter might be cleaner.
Not sure if there are already spellers available.

For Delphi SynEdit there are some plugins available. But those are from after the split/port of SynEdit to Lazarus.

CM630:

--- Quote from: rvk on February 19, 2024, 02:14:50 pm ---Did you mean TSynEdit? TEdit should be single line by default.

--- End quote ---
Yes, I mean tSynEdit, I have fixed my post.


--- Quote from: rvk on February 19, 2024, 02:14:50 pm ---
--- Quote from: CM630 on February 19, 2024, 01:34:01 pm ---2. By default the Delete and the Backspace keys do not work properly. Delete shall erase one character forth, backspace shall erase one character back. But each of them shall erase the selection.
--- End quote ---
Works fine for me in TSynEdit (on Windows).

--- End quote ---

Indeed, on a brand new app it works properly. I must have messed up something.
Edit: After restoring all options to default it works.



--- Quote from: CM630 on February 19, 2024, 01:34:01 pm ---4. When I click with the mouse on an area after the last character of the line, the cursor goes there.
--- End quote ---
Yes, this is default in TSynEdit.
You can exclude TSynEdit.Option the option eoScrollPastEol (and possibly eoScrollPastEof).

Perfect, it works!

Martin_fr:

--- Quote from: CM630 on February 19, 2024, 01:34:01 pm ---1. By default TSynEdit is a multiline control. Does it have a genuine ability to switch single line only mode?

--- End quote ---
You mean pressing "Return" key will not add a new line...

You could edit the key-bindings for that key. But paste can also insert multi-line. And other actions too. You would have to hook them all. Or you would need to add code to SynEdit (might be possible to write a subclass of TSynEditStringsLinked, and add that as via TextViewManager. But that will need quite some research / and I am not sure it will do all you need)



--- Quote ---2. By default the Delete and the Backspace keys do not work properly. Delete shall erase one character forth, backspace shall erase one character back. But each of them shall erase the selection.
This is not happening.
Their actions are defined in the Keystrokes property of TSynEdit, but I cannot find how to define both (conditional) actions per key.

--- End quote ---
This may depend on the options....
- eoPersistentBlock in SynEdit.Options2
- eoOverwriteBlock in SynEdit.Options2
- Any other *block* or *select* in SynEdit.Options and SynEdit.Options2



--- Quote ---3. For some reason after an item is selected from the popup of a TSynCompeltion the Activate event of the main form is triggered. Is this the expected behaviour?

--- End quote ---
The popup is a form of its own.  So that could be (it could also be depending on the WS (gtk,qt,win,....), but I am not sure if it would be)


--- Quote ---4. When I click with the mouse on an area after the last character of the line, the cursor goes there. Is the an option to limit the right (or left in LTF languages) position of the cursor to the rightmost character (like shown on the screenshot)?

--- End quote ---
The (slightly) misnamed eoScrollPastEol in SynEdit.Options

Open the unit SynEditTypes and all the options are listed with comments.


--- Quote ---5. Any guide / info about using a spellchecker with SynEdit is welcome. Shall I create a custom highlighter?

--- End quote ---
Actually a TSynEditMarkup.

But unfortunately that isn't yet documented.

Look at unit SynEditMarkupHighAll; There are several examples in there

- TSynEditMarkupHighlightAll all occurrences of FSearchString
So that could be changed. Instead of comparing with FSearchString, you check the result of the spellchecker.

Your own class can be added via SynEdit.MarkupManager

CM630:



--- Quote from: Martin_fr on February 19, 2024, 05:22:41 pm ---Actually a TSynEditMarkup.


But unfortunately that isn't yet documented.
....

--- End quote ---
That seems to be extremely secret, I could not find a single code snippet.
But somehow, I have guessed that TSynEditMarkupHighlightAll.Create(???); can take a TSynEdit instead of TSynEditBase.


So far 3 problems occurred:
1. MyMarkup.SearchOptions := [ssoWholeWord]; does not work for me (see the screenshot attached).
2. I do not know how to change the colour of the underline.
3. I do not know how to make the underline curly.



--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1;  {$mode objfpc}{$H+}  interface  uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs,  SynEdit, SynEditMarkupHighAll, SynEditMarkup, SynEditTypes;  type    { TForm1 }    TForm1 = class(TForm)    SynEdit1: TSynEdit;    procedure FormCreate(Sender: TObject);  private    public    end;  var  Form1: TForm1;  myMarkup: array of TSynEditMarkupHighlightAll;  implementation  {$R *.lfm}  { TForm1 }  procedure TForm1.FormCreate(Sender: TObject);var  i: integer;begin  SynEdit1.Gutter.Visible := False;  SynEdit1.RightGutter.Visible := False;  SynEdit1.RightEdge := -1;  SynEdit1.Text := 'Ама ти мислиш, че след тая случкъ ни яде ли вече по толкова?' + #13#10 + 'По идно кринче варени картофи излапва като нищо, една тиква и четири печени царевици отгоре за мезе. Само вода ни пие веднага. Диета пази. Фелдшерът тъй му поръчал.';    if SynEdit1.MarkupManager.Count > 0 then    while SynEdit1.MarkupManager.Count > 0  do      SynEdit1.MarkupManager.RemoveMarkUp(SynEdit1.MarkupManager.Markup[0]);    SetLength(myMarkup,3);  for i := 0 to high(myMarkup) do  begin    MyMarkup[i] :=  TSynEditMarkupHighlightAll.Create(SynEdit1);    MyMarkup[i].SearchOptions := [ssoWholeWord];    myMarkup[i].MarkupInfo.Background := clNone;    myMarkup[i].MarkupInfo.Foreground := clDefault;//  myMarkup.MarkupInfo.FrameColor := clBlue;    myMarkup[i].MarkupInfo.Style :=  [TFontStyle.fsUnderline];    SynEdit1.MarkupManager.AddMarkUp(MyMarkup[i]);  end; //for  myMarkup[0].SearchString := 'случкъ';  myMarkup[1].SearchString := 'ни';  myMarkup[2].SearchString := 'идно';end;  end. 

Navigation

[0] Message Index

[#] Next page

Go to full version