Difference between revisions of "Talk:SynEdit"

From Free Pascal wiki
Jump to navigationJump to search
m
Line 1: Line 1:
= Repl =
+
= Repl example =
  
  var p1,p2: TPoint;
+
::: How to write examp, which replaces string from (x=2,y=10) to (x=4,y=20) with string S ? [[User:Alex22|Alex22]]
  begin
 
    p1 := SynEdit.LogicalCaretXY;
 
    p2 := SynEdit.LogicalCaretXY;
 
    p2.x := p2.x + UTF8CharacterLength(@SynEdit.LineText[p2.x]); // byte len of char AFTER current caret
 
    SynEdit.TextBetweenPoints[p1,p2] := '';
 
 
 
Bad example. What it must do? replace One char with empty string? Show example how to replace 4 chars with S string. [[User:Alex22|Alex22]] 03:55, 12 June 2014 (CEST)
 
 
 
:: Improved example. How to calculate bytepos of a utf8 char is not a SynEdit topic. This should be covered on its owe wiki page / or on a page related to utf8. If exists it can be linked. - Martin
 
 
 
::: How to write examp, which replaces string from (x=2,y=10) to (x=4,y=20) with string S ?  
 
::: b) better remove @SynEdit.LineText[p2.x] , it's not good for exm. [[User:Alex22|Alex22]]
 
  
 
:::: if x=2/y=10 are correct logical positions (1-based first byte pos of a char)
 
:::: if x=2/y=10 are correct logical positions (1-based first byte pos of a char)
 
:::: (there is a unit that defines the function point / use codetools to find, it, or assign by hand to p.x/p.y of point)
 
:::: (there is a unit that defines the function point / use codetools to find, it, or assign by hand to p.x/p.y of point)
:::: Last byte replaced is at x=3 y=20
+
:::: Last byte replaced is at x=4 y=20
 
::::  SynEdit.TextBetweenPoints[point(2,10),point(4,20)] := s;
 
::::  SynEdit.TextBetweenPoints[point(2,10),point(4,20)] := s;
 
:::: This is identical to setting the text selection, and replacing it. Except, this can keep the current selection. -- Martin
 
:::: This is identical to setting the text selection, and replacing it. Except, this can keep the current selection. -- Martin
  
 
:::: Feel free to improve the example. But make sure people notice it is byte pos in utf8
 
:::: Feel free to improve the example. But make sure people notice it is byte pos in utf8

Revision as of 20:32, 12 June 2014

Repl example

How to write examp, which replaces string from (x=2,y=10) to (x=4,y=20) with string S ? Alex22
if x=2/y=10 are correct logical positions (1-based first byte pos of a char)
(there is a unit that defines the function point / use codetools to find, it, or assign by hand to p.x/p.y of point)
Last byte replaced is at x=4 y=20
SynEdit.TextBetweenPoints[point(2,10),point(4,20)] := s;
This is identical to setting the text selection, and replacing it. Except, this can keep the current selection. -- Martin
Feel free to improve the example. But make sure people notice it is byte pos in utf8