Page 1 of 1

Get a line of text using Scintilla

Posted: Thu Aug 28, 2025 1:48 pm
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.

Re: Get a line of text using Scintilla

Posted: Thu Aug 28, 2025 3:06 pm
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.

Re: Get a line of text using Scintilla

Posted: Thu Aug 28, 2025 3:18 pm
by infratec

Re: Get a line of text using Scintilla

Posted: Thu Aug 28, 2025 3:30 pm
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

Re: Get a line of text using Scintilla

Posted: Fri Aug 29, 2025 4:59 pm
by Ross Carter
Thank you for the code on Get a line of text using Scintilla, it works fine.

Re: Get a line of text using Scintilla

Posted: Fri Aug 29, 2025 5:22 pm
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