* * *

Author Topic: Doubt in comment single line with latin characters  (Read 556 times)

jcfaria

  • Newbie
  • Posts: 4
Doubt in comment single line with latin characters
« on: December 16, 2017, 11:52:25 am »
Hi all,

I have many instances of default SynEdit class in my application. So, A small procedure was performed (see below) to comments (under SQL highlighter).

The problem: if I have a single line to be commented and it has latin characters, the final comment symbol is not positioned correctly. For example:

I want to comment the line below:

test áéíóú


The result from the procedure is the below:

/*test áéíóú*/íóú 


For selection it is working fine. I do not want to use the same solution for single line to not lose undo / redo resource in the instances of the class.

How can I fix this?
 :-[

Code: Pascal  [Select]
  1. procedure pSyn_Comentar(synEdt: TSynEdit);
  2. var
  3.   sTMP: string;
  4.   i   : integer;
  5.  
  6. begin
  7.   with synEdt do begin
  8.     BeginUpdate;
  9.  
  10.     if (SelText = '') then begin  // Will comment the line where the cursor is
  11.       sTMP:= LineText;
  12.  
  13.       i:= CaretX;
  14.  
  15.       CaretX:= 0;
  16.       ExecuteCommand(ecDeleteEOL,
  17.                      #0,
  18.                      nil);
  19.  
  20.       SelText:= '/*' +
  21.                 sTMP +
  22.                 '*/';
  23.  
  24.       CaretX:= i + 2;  // Return the cursor to the original position
  25.     end
  26.     else  // Comment on the selection
  27.       SelText:= '/*' +
  28.                 SelText +
  29.                 '*/';
  30.  
  31.     EndUpdate;
  32.   end;
  33. end;
  34.  
« Last Edit: December 16, 2017, 03:06:55 pm by jcfaria »

Thaddy

  • Hero Member
  • *****
  • Posts: 5168
Re: Doubt in comment single line with latin characters
« Reply #1 on: December 16, 2017, 12:28:22 pm »
Hi all,

I have many instances of default SynEdit class. So, I make a simple procedure (below) to comment (SQL highlighter).

The problem is, if the single line to be commented has Latin characters, the final comment symbol is not positioned correctly. For example:


test áéíóú
/*test áéíóú*/íóú 


How can I fix this?
 :-[

Code: Pascal  [Select]
  1. procedure pSyn_Comentar(synEdt: TSynEdit);
  2. var
  3.   sTMP: string;
  4.   i   : integer;
  5.  
  6. begin
  7.   with synEdt do begin
  8.     BeginUpdate;
  9.  
  10.     if (SelText = '') then begin  // Will comment the line where the cursor is
  11.       sTMP:= LineText;
  12.  
  13.       i:= CaretX;
  14.  
  15.       CaretX:= 0;
  16.       ExecuteCommand(ecDeleteEOL,
  17.                      #0,
  18.                      nil);
  19.  
  20.       SelText:= '/*' +
  21.                 sTMP +
  22.                 '*/';
  23.  
  24.       CaretX:= i + 2;  // Return the cursor to the original position
  25.     end
  26.     else  // Comment on the selection
  27.       SelText:= '/*' +
  28.                 SelText +
  29.                 '*/';
  30.  
  31.     EndUpdate;
  32.   end;
  33. end;
  34.  
/*test áéíóú*/íóú   is not a Pascal comment but a C style comment and needs termination with */ because it is multiline.
i.e. /* ..... */
Pascal rules:
// doubleforward slash is a single line comment, like in C++ (not C officially)
{ } delimits a multiline comment
(* *) delimits a multiline comment.

What are you trying to achieve?
« Last Edit: December 16, 2017, 12:32:48 pm by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

jcfaria

  • Newbie
  • Posts: 4
Re: Doubt in comment single line with latin characters
« Reply #2 on: December 16, 2017, 01:13:01 pm »
Sorry, the original question was not well formulated and was redone. I am commenting a single line in SQL. The higlighter properties is a TSynSQLSyn object.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4449
    • wiki
Re: Doubt in comment single line with latin characters
« Reply #3 on: December 16, 2017, 06:02:54 pm »
Just tested, you found a bug in ecDeleteEOL.

You can use 
Code: Pascal  [Select]
  1. SynEdit.SelectLine;
and then replace the selection.

Or SetTextBetweenPoints instead:
http://wiki.lazarus.freepascal.org/SynEdit#Change_text_from_code
http://wiki.lazarus.freepascal.org/SynEdit#Logical.2FPhysical_caret_position

--------------- EDIT
https://bugs.freepascal.org/view.php?id=32838

Also CaretX afaik starts at 1.
CaretX:=0 is not correct.

« Last Edit: December 16, 2017, 06:26:52 pm by Martin_fr »

jcfaria

  • Newbie
  • Posts: 4
Re: Doubt in comment single line with latin characters
« Reply #4 on: December 17, 2017, 11:37:03 pm »
It works!
Thanks for all.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4449
    • wiki
Re: Doubt in comment single line with latin characters
« Reply #5 on: January 14, 2018, 01:22:41 am »
The ecDeleteEOL should be fixed in upcoming 1.8.2

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus