Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gets the text inside the subfunction
#5
@Kevin

I found a new solution:

As a prerequisite, the text cursor is placed at the end of the first line of the subfunction (red arrow in the image)
then I can get the position of the beginning of the line where the cursor is (blue arrow in the figure)
then through the Find function, navigate to the beginning of the next # line (Pink arrow in the figure), It can be a bit complicated to implement
then Create a text area between two # lines (from the red arrow to the pink arrow)
Finally, I can copy and replace the text

There are two related functions that follow for reference, and I don't have the ability to implement full functionality at the moment


[Image: b.png]

I found a private function SciGetSelText in QM's system folder

[Image: a.png]

The code is as follows:
 
Code:
Copy      Help
#sub SciGetSelText
function# h str&s ;;Returns sel start. If h 0, calls GetQmCodeEditor.

if(!h) h=GetQmCodeEditor
TEXTRANGE t
t.chrg.cpMin=SendMessage(h SCI.SCI_GETSELECTIONSTART 0 0)
t.chrg.cpMax=SendMessage(h SCI.SCI_GETSELECTIONEND 0 0)
t.lpstrText=s.all(t.chrg.cpMax-t.chrg.cpMin)
s.fix(SendMessage(h SCI.SCI_GETTEXTRANGE 0 &t))
ret t.chrg.cpMin

I define the function SciGetCurLineText
It can get the text of the line where the cursor is located

 
Code:
Copy      Help
out
int j=sub.SciGetCurLineText(0 str'ls)
out ls
;
;str s="bbb"
;SendMessage(h SCI.SCI_REPLACESEL 0 s)

#sub SciGetCurLineText
function# h str&s ;;Returns the text of the line where the current cursor is located. If h 0, calls GetQmCodeEditor.

if(!h) h=GetQmCodeEditor
TEXTRANGE t

int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
int lineN=SendMessage(h SCI.SCI_LINEFROMPOSITION cp 0)
int lineLen=SendMessage(h SCI.SCI_LINELENGTH lineN 0)
int lineEnd=SendMessage(h SCI.SCI_GETLINEENDPOSITION lineN 0)

t.chrg.cpMin=lineEnd-lineLen+2
t.chrg.cpMax=lineEnd
t.lpstrText=s.all(t.chrg.cpMax-t.chrg.cpMin)
s.fix(SendMessage(h SCI.SCI_GETTEXTRANGE 0 &t))
ret t.chrg.cpMin


Messages In This Thread
Gets the text inside the subfunction - by Davider - 11-27-2022, 03:12 AM
RE: Gets the text inside the subfunction - by Davider - 11-30-2022, 10:47 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)