Get a line of text using Scintilla

Just starting out? Need help? Post your questions and find answers here.
Ross Carter
New User
New User
Posts: 5
Joined: Thu May 11, 2023 2:56 pm
Location: Portsmouth, Uk

Get a line of text using Scintilla

Post by Ross Carter »

Is there a way to get a line of text at the cursor position within an edit window and put that line into a string using Scintilla. I would be grateful for any help.
Axolotl
Addict
Addict
Posts: 832
Joined: Wed Dec 31, 2008 3:36 pm

Re: Get a line of text using Scintilla

Post by Axolotl »

Could you please be more specific with your request?
Otherwise, the answer can only be yes.
Sorry, but maybe I just don't understand.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
infratec
Always Here
Always Here
Posts: 7613
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Get a line of text using Scintilla

Post by infratec »

infratec
Always Here
Always Here
Posts: 7613
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Get a line of text using Scintilla

Post by infratec »

Code: Select all

If OpenWindow(0, 0, 0, 330, 120, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
    ScintillaGadget(0, 5, 5, 320, 80, 0)
    *Text = UTF8("This is a simple ScintillaGadget with text..." + #LF$ + "More text" + #LF$ + "Even more text!")
    ScintillaSendMessage(0, #SCI_SETTEXT, 0, *Text)
    FreeMemory(*Text) ; der von UTF8() erstellte Puffer muss freigegeben werden, um ein Speicherleck zu vermeiden
    
    ButtonGadget(1, 10, 90, 200, 20, "Copy line with cursor in it")
    
    Repeat
      Event = WaitWindowEvent()
      Select Event
        Case #PB_Event_Gadget
          If EventGadget() = 1
            *buffer = AllocateMemory(1024)
            If *buffer
              ScintillaSendMessage(0, #SCI_GETCURLINE, MemorySize(*buffer) - 1, *buffer)
              Debug PeekS(*buffer, -1, #PB_UTF8)
              FreeMemory(*buffer)
            EndIf
          EndIf
      EndSelect
      
    Until Event = #PB_Event_CloseWindow

  EndIf
Ross Carter
New User
New User
Posts: 5
Joined: Thu May 11, 2023 2:56 pm
Location: Portsmouth, Uk

Re: Get a line of text using Scintilla

Post by Ross Carter »

Thank you for the code on Get a line of text using Scintilla, it works fine.
AZJIO
Addict
Addict
Posts: 2183
Joined: Sun May 14, 2017 1:48 am

Re: Get a line of text using Scintilla

Post by AZJIO »

https://azjio.narod.ru/PureBasic/pb_use ... ETTEXT.htm

Code: Select all

Procedure.s GetScintillaGadgetText()
    Protected txtLen, *mem, text$
    txtLen = ScintillaSendMessage(#SciGadget, #SCI_GETLENGTH) ; получает длину текста в байтах
    *mem = AllocateMemory(txtLen + 2) ; Выделяем память на длину текста и 1 символ на Null
    If *mem ; Если указатель получен, то
        ScintillaSendMessage(#SciGadget, #SCI_GETTEXT, txtLen + 1, *mem) ; получает текст
        ; Считываем значение из области памяти
        If g_Format = #PB_Ascii
            text$ = PeekS(*mem, -1, #PB_Ascii)
        Else
            text$ = PeekS(*mem, -1, #PB_UTF8)
        EndIf                        
        FreeMemory(*mem)
        ProcedureReturn text$
    EndIf
    ProcedureReturn ""
EndProcedure
Post Reply