Forum > Packages and Libraries

TATSynEdit - Getting lines with selected text

(1/1)

SaraT:
Hi, coders

Using a loop for, I  would like to add a char dollar "$" at the beginning of lines which have any selected text.
Ignore the current line if it does not have any selected text.

Can someone help me providing a working code?
Thanks in advance.

cdbc:
Hi Sara
I'm not quite sure what you mean, but I think it could be what this unit below does:
--- 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 sarat.marktext; {$mode ObjFPC}{$H+} interface uses  Classes, SysUtils, LazUTF8;{ Takes the 'aMask' to search for and the 'aList' of strings to search in +  you can specify case-sensivity, returns the number of changes made }function MarkTexts(const aMask: string;aList: TStrings;aCaseSensitive: boolean = true): ptrint; implementation function MarkTexts(const aMask: string; aList: TStrings; aCaseSensitive: boolean): ptrint;var li: ptrint = 0; lomask, ls: string;begin  if ((aMask = '') or (aList.Count = 0)) then exit(0); { nothing to do }  if not aCaseSensitive then lomask:= UTF8LowerCase(aMask);  Result:= 0;  for li:= 0 to aList.Count-1 do begin    if aCaseSensitive then begin // sensitive      if UTF8Pos(aMask,aList[li]) > 0 then begin        ls:= aList[li];        insert('$',ls,1);        aList[li]:= ls;        inc(Result);      end;    end else begin               // INsensitive      if UTF8Pos(lomask,UTF8LowerCase(aList[li])) > 0 then begin         ls:= aList[li];        insert('$',ls,1);        aList[li]:= ls;        inc(Result);      end;    end;  end;end;  end. HTH
Regards Benny

AlexTP:
I overlooked this post.

ATSynEdit has Carets property. Read all Carets items and detect which lines are affected by selection(s).

Then use Strings property which has list of lines. To add dollar at line beginning:


--- 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";}};} ---Editor1.Strings.Lines[i]:= '$'+Editor1.Strings.Lines[i];

Navigation

[0] Message Index

Go to full version