Forum > SynEdit
how to get line number of text under mouse.position
Josh:
Hi
Is it possible to get the line number of the text under the current mouse location; without modifying the caret position.
Ideally without having the synedit as active control,
Am trying to analyze contents of multiple synedit by just moving the mouse over the text, without selecting any.
At the moment am using applicationproperties.onuserinput to intercept mouse movement and detect the control under cursor position.
--- 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";}};} ---var Msg: Cardinal); cntrl:TControl;begin if msg<>LM_MOUSEMOVE then exit; cntrl:= FindLCLControl(mouse.CursorPos); if cntrl is TSynEdit then begin .. // ctrl under mouse is tsynedit end
DomingoGP:
Hi,
Maybe this code works for you.
Regards
Domingo.
--- 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";}};} ---uses lmessages, SynEditTypes; procedure TForm1.OnUserInputEvent(Sender: TObject; Msg: cardinal);var cntrl: TControl; cntrlPos: TPoint; rowColumn: TPoint;begin if msg <> LM_MOUSEMOVE then exit; cntrl := FindLCLControl(mouse.CursorPos); if cntrl is TSynEdit then begin cntrlPos := cntrl.ScreenToControl(mouse.CursorPos); rowColumn := TSynEdit(cntrl).PixelsToRowColumn(cntrlPos, [scmIncludePartVisible]); if rowColumn.Y <= TSynEdit(cntrl).Lines.Count then Label1.Caption := 'Line: ' + IntToStr(rowColumn.Y) else Label1.Caption := ''; end else label1.Caption := '';end;
Josh:
Hi DomingoGP
Thanks that had the info needed. :)
First time i've used SynEdit so probably have more questions.
--- 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";}};} ---var Msg: Cardinal); cntrl:TControl; LineUnderMouse:AnsiString='';begin if msg<>LM_MOUSEMOVE then exit; cntrl:= FindLCLControl(mouse.CursorPos); if cntrl is TSynEdit then begin // ctrl under mouse is tsynedit LineUnderMouse:=TSynEdit(cntrl).Lines[(tpoint(TSynEdit(cntrl).PixelsToRowColumn(tpoint(cntrl.ScreenToControl(mouse.CursorPos)),[scmIncludePartVisible])).Y)-1]); end;
Thanks
DomingoGP:
You are welcome.
You should check that the line is not greater than TSynEdit(cntrl).lines.count.
For example if the editor has only 2 lines of text and you move the cursor below the second line it will fail when you access TSynEdit(cntrl).lines[3].
Martin_fr:
From SynEdit
--- 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";}};} --- // Pixel function ScreenColumnToXValue(Col: integer): integer; // map screen column to screen pixel function ScreenXYToPixels(RowCol: TPhysPoint): TPoint; // converts screen position (1,1) based function RowColumnToPixels(RowCol: TPoint): TPoint; // deprecated 'use ScreenXYToPixels(TextXYToScreenXY(point))'; function PixelsToRowColumn(Pixels: TPoint; aFlags: TSynCoordinateMappingFlags = [scmLimitToLines]): TPoint; function PixelsToLogicalPos(const Pixels: TPoint): TPoint; // function ScreenRowToRow(ScreenRow: integer; LimitToLines: Boolean = True): integer; override; deprecated 'use ScreenXYToTextXY'; function RowToScreenRow(PhysicalRow: integer): integer; override; deprecated 'use TextXYToScreenXY'; (* ScreenXY: First visible (scrolled in) screen line is 1 First column is 1 => column does not take scrolling into account *) function ScreenXYToTextXY(AScreenXY: TPhysPoint; LimitToLines: Boolean = True): TPhysPoint; override; function TextXYToScreenXY(APhysTextXY: TPhysPoint): TPhysPoint; override;
Logical/Physical https://wiki.freepascal.org/SynEdit#Logical.2FPhysical_caret_position
You could use the PixelsTO.... function
PixelsToRowColumn is physical.
PixelsToLogicalPos is the byte in the line text.
Navigation
[0] Message Index
[#] Next page