Editor Gadget

Just starting out? Need help? Post your questions and find answers here.
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Editor Gadget

Post by eck49 »

Am I missing a trick with the Editor Gadget?

If I run this code based on the example code from the manual...

Code: Select all

  LoadFont(77,"Arial",28)
  If OpenWindow(0, 0, 0, 622, 500, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
    EditorGadget(0, 8, 8, 306, 433)
    SetGadgetAttribute(0,#PB_Editor_ReadOnly,0)   ;0 means editable, but the same happens for Read-only
    SetGadgetColor(0,#PB_Gadget_FrontColor,RGB(0,50,50))
    SetGadgetColor(0,#PB_Gadget_BackColor,RGB(190,190,0))
    SetGadgetFont(0,FontID(77))
    For a = 0 To 500
      AddGadgetItem(0, a, "Line "+Str(a))
    Next
    Delay(3)
    Repeat
      zEvent = WaitWindowEvent()
      Select zEvent
        Case #PB_Event_CloseWindow
          Break
      EndSelect
    ForEver
  EndIf
and then scroll down a few lines in the inner window, the top and bottom of the inner window become hidden by a stripe of the background colour, so that (with this size of font) one line of text at the top and bottom of the window are no longer visible. The height of the stripe is independent of the font as well as its size and it is not simply an exact number of text lines. The initial display (Line 0 etc) and the end of the list (Line 500 etc) show up properly when scrolling fully to the top and bottom.

I've looked for a report of this unwanted phenomenon on the forum or a flag to set to get rid of it without success. Is it just on Linux? What can I do about it?


PS - off topic but relevant: I could put up a screenshot, but how do I insert an image on here - without uploading it somewhere else first? The img button seems to expect a URL.
EDIT: I've found in the FAQ the answer to my PS. The answer is that I can't.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
BarryG
Addict
Addict
Posts: 4226
Joined: Thu Apr 18, 2019 8:17 am

Re: Editor Gadget

Post by BarryG »

eck49 wrote:Is it just on Linux?
On your Linux version: yes. Your problem doesn't happen to me on Windows when I run it, and probably not on other Linux variants. That's the problem with Linux: too many variations.
eck49 wrote:What can I do about it?
Try first to update any video drivers for your version of Linux. If that still fails, post a bug report in the Linux section of these forums, preferably with a link to a short video showing the issue.
eck49 wrote:how do I insert an image on here - without uploading it somewhere else first?
Open a free account at https://imgur.com and upload them there, then copy their URLs for pasting into posts here. It's what most people do, both in these forums and elsewhere. You can also upload videos to Imgur (per my above comment).
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Editor Gadget

Post by juergenkulow »

Hello eck49,

try Scintilla.
Please ask your questions, because switch on the cognition apparatus decides on the only known life in the universe.Wersten :DDüsseldorf NRW Germany Europe Earth Solar System Flake Bubble Orionarm
Milky Way Local_Group Virgo Supercluster Laniakea Universe
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4996
Joined: Sun Apr 12, 2009 6:27 am

Re: Editor Gadget

Post by RASHAD »

With Windows it's known as (AutoScroll Point Position) problem
Don't know about other O Sytems
Egypt my love
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: Editor Gadget

Post by eck49 »

Thank you all.

@juergenkulow:
I did look at Scintilla, but it is a serious overkill for my needs in this context. Even the editor gadget is over-powerful. A scrollable text gadget would serve, which is an idea I might pursue.

@BarryG:
Interestingly, I compiled an exe on this version of Ubuntu and then ran it on an older version (same hardware) and the gadget behaved perfectly.
Thanks for the pointer to imgur. The other forum I contribute to sometimes allows direct insertion of images as long as they are not too large.

It looks from RASHAD's post as though it is not a problem unknown to Windows in some contexts.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
AZJIO
Addict
Addict
Posts: 2230
Joined: Sun May 14, 2017 1:48 am

Re: Editor Gadget

Post by AZJIO »

If you remove this line, it works fine

Code: Select all

SetGadgetColor(0,#PB_Gadget_BackColor,RGB(190,190,0))
BarryG
Addict
Addict
Posts: 4226
Joined: Thu Apr 18, 2019 8:17 am

Re: Editor Gadget

Post by BarryG »

eck49 wrote:I compiled an exe on this version of Ubuntu and then ran it on an older version (same hardware) and the gadget behaved perfectly.
That's why I suspect it's your installed video drivers, that aren't 100% working.
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Editor Gadget

Post by juergenkulow »

Hello eck49,

Code: Select all

; Simple Edit with ScintillaGadget in fullscreen.
EnableExplicit  
ExamineDesktops()
If OpenWindow(0, DesktopX(0), DesktopY(0), DesktopWidth(0),DesktopHeight(0), "", #PB_Window_BorderLess)
  If InitScintilla()
    ScintillaGadget(0, 0,0,DesktopWidth(0),DesktopHeight(0), 0)
    Define s.s : s="Line: 1"
    Define i : For i=2 To 500     ; Starting Text 
      Define s.s : s+#LF$+"Line: "+Str(i)
    Next  
    Define *Text = UTF8(s)
    ScintillaSendMessage(0, #SCI_SETTEXT, 0, *Text) ; Send Line 1 to 500 to Scintilla
    FreeMemory(*Text) 
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow ; Mainloop left with F4    
    Define len.l = ScintillaSendMessage(0, #SCI_GETLENGTH) + 1 ;Receive length of the text. 
    Define *mem = AllocateMemory(len)
    If *mem
      ScintillaSendMessage(0, #SCI_GETTEXT, len, *mem) ; Receive text from scintilla. 
      Debug PeekS(*mem,len,#PB_UTF8)                   ; Do what ever you want with the text.
      FreeMemory(*mem)
    EndIf
  EndIf 
EndIf
AZJIO
Addict
Addict
Posts: 2230
Joined: Sun May 14, 2017 1:48 am

Re: Editor Gadget

Post by AZJIO »

juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Editor Gadget

Post by juergenkulow »

@AZJIO,
can you please give some information about constants in your source code:

Code: Select all

#SC_C_CP_UTF8=65001 ;???

#SCI_SSCI_SETADDITIONALCARETSBLINK=
#SCI_SSCI_SETADDITIONALSELPHA=
#SCI_SSCI_SETADDITIONALSELBACK=
#SCI_SSCI_SETADDITIONALSELFORE=
#SCI_SSCI_SETRECTANGULARSELECTIONMODIFIER=
By the way, the deepl translation:

Code: Select all

;AZJIO Example Scintilla 
#SC_C_CP_UTF8=65001 ;???

;#SCI_SSCI_SETADDITIONALCARETSBLINK=
;#SCI_SSCI_SETADDITIONALSELPHA=
;#SCI_SSCI_SETADDITIONALSELBACK=
;#SCI_SSCI_SETADDITIONALSELFORE=
;#SCI_SSCI_SETRECTANGULARSELECTIONMODIFIER=
EnableExplicit
InitScintilla()

; #MENU_EXTEND_SELECTION=10
Define txt$, txtLen, marginWidth, Gadget
Declare Color(*regex, regexLength, n)
Declare Color2(*regex, regexLength, n)
Declare MakeUTF8Text(text.s)
Declare MakeScintillaText(text.s, *sciLength.Integer=0)
Declare OpenFileR(*sciLength.Integer=0)
Declare SciNotification(Gadget, *scinotify.SCNotification)
Declare ReadFileR(Path$)

; Procedure ExtendScintillaSelection()
; Protected mainSel, selStart, selEnd
; mainSel=ScintillaSendMessage(0, #SCI_GETMAINSELECTION)
; selStart=ScintillaSendMessage(0, #SCI_GETSELECTIONNSTART, mainSel)
; selEnd=ScintillaSendMessage(0, #SCI_GETSELECTIONNEND, mainSel)
;
; EndProcedure.

txt$="Insert test "+#LF$+
"you can use this code as an example to work with Scintilla "+#LF$+
"link http://purebasic.info/phpBB3ex/index.php "+#LF$+
"This is search, markers, styling, etc. 2222"+#LF$
; Define i
; For i = 1 To 500
; txt$+#LF$+"Line: "+Str(i)
; Next 
txtLen=StringByteLength(txt$, #PB_UTF8)


OpenWindow(100, 0, 0, 900, 600, "Scintilla Editor", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget)

; Creating a gadget the size of the entire window
ScintillaGadget(0, 0, 0, WindowWidth(100), WindowHeight(100), @SciNotification())
; Sets text mode
ScintillaSendMessage(0, #SCI_SETWRAPMODE, #SC_WRAP_NONE) ; without line break
ScintillaSendMessage(0, #SCI_SETCODEPAGE, #SC_C_CP_UTF8) ; UTF-8 encoding
														 ; ScintillaSendMessage(0, #SCI_SETVIRTUALSPACEOPTIONS, #SCVS_RECTANGULARSELECTION | #SCVS_USERACCESSIBLE) ; allow cursor and selection outside of end of line
														 ; Sets current line highlighting
ScintillaSendMessage(0, #SCI_SETCARETLINEVISIBLE, 1) ; highlight the current string
ScintillaSendMessage(0, #SCI_SETCARETLINEVISIBLE, 1) ; highlights always, even if focus is lost
														   ; ScintillaSendMessage(0, #SCI_SETCARETLINEBACKALPHA, 255) ; the current line's backlight transparency (0-255), 255 is 100% transparent
ScintillaSendMessage(0, #SCI_SETCARETLINEBACK, RGB(0, 0, 0)) ; highlight string colour
															 ; Sets text style
ScintillaSendMessage(0, #SCI_STYLESETFONT, #STYLE_DEFAULT, MakeUTF8Text("Arial")) ; the selection rectangle works better with the monospace font Courier New
ScintillaSendMessage(0, #SCI_STYLESETBACK, #STYLE_DEFAULT, RGB(63, 63, 63)) ; the background colour
ScintillaSendMessage(0, #SCI_STYLESETFORE, #STYLE_DEFAULT, RGB(153, 153, 153)) ; the colour of text
ScintillaSendMessage(0, #SCI_STYLECLEARALL)
; Sets indent size and style of line number column
ScintillaSendMessage(0, #SCI_STYLESETFONT, #STYLE_LINENUMBER, MakeUTF8Text("Arial")) ; the font of line numbers
ScintillaSendMessage(0, #SCI_STYLESETBACK, #STYLE_LINENUMBER, RGB(33, 33, 33)) ; the background colour of the lines number field
ScintillaSendMessage(0, #SCI_STYLESETFORE, #STYLE_LINENUMBER, RGB(153, 153, 153)) ; the colour of the text of the line number field
marginWidth=ScintillaSendMessage(0, #SCI_TEXTWIDTH, #STYLE_LINENUMBER, MakeUTF8Text("_999")) ; the width of the row number field
ScintillaSendMessage(0, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)
ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 0, marginWidth) ; Sets the width of the row number field
marginWidth=0
ScintillaSendMessage(0, #SCI_SETMARGINMASKN, 2, #SC_MASK_FOLDERS) ; Set margin for the convolution margin
ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 2, marginWidth) ; Sets the width of the convolution margin
ScintillaSendMessage(0, #SCI_SETMARGINSENSITIVEN, 2, #True) ; Set sensitivity of the margin to click
;																  Set cursor text style And selection
ScintillaSendMessage(0, #SCI_SETCARETSTICKY, 1) ; makes always visible (?)
ScintillaSendMessage(0, #SCI_SETCARETWIDTH, 1) ; the text cursor thickness
ScintillaSendMessage(0, #SCI_SETCARETFORE, RGB(255, 255, 255)) ; the colour of the text cursor
ScintillaSendMessage(0, #SCI_SETSELALPHA, 100) ; the transparency of the selection
ScintillaSendMessage(0, #SCI_SETSELBACK, 1, RGB(255, 255, 255)) ; the background colour of the selection
ScintillaSendMessage(0, #SCI_SETSELFORE, 1, RGB(160, 160, 160)) ; highlight text colour
                                                                ; Sets additional styles If multiple cursors And selections are used
ScintillaSendMessage(0, #SCI_SETADDITIONALCARETFORE, RGB(255, 160, 160)) ; the colour of the additional text cursor
;;ScintillaSendMessage(0, #SCI_SSCI_SETADDITIONALCARETSBLINK, 1) ; the additional text cursor is blinking
;;ScintillaSendMessage(0, #SCI_SSCI_SETADDITIONALSELPHA, 100) ; the transparency of the additional selection
;;ScintillaSendMessage(0, #SCI_SSCI_SETADDITIONALSELBACK, RGB(255, 255, 100))	 ; the background colour of the additional selection
;;ScintillaSendMessage(0, #SCI_SSCI_SETADDITIONALSELFORE, RGB(255, 255, 130))	 ; the colour of the text of the additional selection
;																		 Enables multiple cursor
;;ScintillaSendMessage(0, #SCI_SSCI_SETRECTANGULARSELECTIONMODIFIER, #SCMOD_ALT) ; highlight while holding down the Alt key
ScintillaSendMessage(0, #SCI_SETMULTIPLESELECTION, 1) ; allows to select several times by holding down CTRL or CMD
ScintillaSendMessage(0, #SCI_SETMULTIPASTE, #SC_MULTIPASTE_EACH) ; multiple insertion of text
ScintillaSendMessage(0, #SCI_SETADDITIONALSELECTIONTYPING, 1) ; allows inputting text, moving cursor, etc. in multiple places at once

; ScintillaSendMessage(0, #SCI_USEPOPUP, 1)
; ScintillaSendMessage(0, #SCI_SETVSCROLLBAR, 1) ; Vertical scrollbar always

; Allow hotkey CTRL + D for additional auto-allocate.
; AddKeyboardShortcut(100, #PB_Shortcut_Control | #PB_Shortcut_D, #MENU_EXTEND_SELECTION)
; BindEvent(#PB_Event_Menu, ExtendScintillaSelection())


ScintillaSendMessage(0, #SCI_SETTEXT, 0, MakeUTF8Text(txt$)) ; Set gadget text
ScintillaSendMessage(0, #SCI_GOTOPOS, txtLen) ; Cursor at end of text
SetActiveGadget(0) ; Set gadget active, input focus

; These constants will be used for the syntax highlighting.
Enumeration 0
	#LexerState_Space
	#LexerState_Number
	#LexerState_Keyword
	#LexerState_String
	#LexerState_Preprocessor
	#LexerState_Operator
	#LexerState_Comment
	#LexerState_FoldKeyword
EndEnumeration
ScintillaSendMessage(0, #SCI_STYLESETFORE, #LexerState_Comment, RGB(113, 174, 113)) ; The colour of the comment
ScintillaSendMessage(0, #SCI_STYLESETFORE, #LexerState_Number, $ABCEE3) ; The colour of the numbers, BGR
ScintillaSendMessage(0, #SCI_STYLESETFORE, #LexerState_Keyword, $FF9F00) ; The colour of the keyword, BGR
ScintillaSendMessage(0, #SCI_STYLESETFORE, #LexerState_Preprocessor, $DE97D9) ; The colour of the preprocessor, BGR
ScintillaSendMessage(0, #SCI_STYLESETFORE, #LexerState_Operator, $8080FF) ; The colour of the preprocessor, BGR
ScintillaSendMessage(0, #SCI_STYLESETFORE, #LexerState_FoldKeyword, RGB(0, 136, 0))	; The colour of the keywords with the minimize.
ScintillaSendMessage(0, #SCI_STYLESETBOLD, #LexerState_Number, 1) ; Emphasize numbers in bold type
ScintillaSendMessage(0, #SCI_STYLESETITALIC, #LexerState_Comment, 1) ; Emphasize comments in slanted font
																					; MessageRequester(Str(#STYLE_LINENUMBER) , Str(#STYLE_DEFAULT)) ; here we check constants of other styles, if they do not interfere

; For RGB from web
; Global num.i = Val("$71AE71")
; Global num_text.s = Str(Red(num)) + ", " + Str(Green(num)) + ", " + Str(Blue(num))
; Debug num_text ; Displays the colour in RGB function format

; Trying to apply the style (positioning and length issue)
ScintillaSendMessage(0, #SCI_STARTSTYLING, 50, 0) ; start position (from 50th)
ScintillaSendMessage(0, #SCI_SETSTYLING, 14, #LexerState_Comment) ; width and style number

If CreateMenu(0, WindowID(100)) ;  Here start menu creation....
	MenuTitle("Menu")
	MenuItem(1, "Open file")
	MenuItem(2, "Insert current date")
	MenuItem(3, "Paste from clipboard")
	MenuBar() ; separator
	MenuItem(4, "Exit")
	MenuItem(5, "Find numbers (indicators)")
	MenuItem(6, "Find numbers (style)")
	MenuItem(7, "Clear Style")
EndIf

Global Event, em, Text$, TextLength, regex$
Repeat
	Event = WaitWindowEvent()
	Select Event
		Case #PB_Event_SizeWindow
			ResizeGadget(0, #PB_Ignore, #PB_Ignore, WindowWidth(100), WindowHeight(100))
		Case #PB_Event_Menu
			em = EventMenu()
			Select em
				Case 1
					OpenFileR()
				Case 2
					Text$ = FormatDate("%dd.%mm.%yyyy", Date()) ;Returns current date
					; ScintillaSendMessage(0, #SCI_APPENDTEXT, Len(Text$), MakeUTF8Text(Text$)) ; does not work with UTF-8
					 ; ScintillaSendMessage(0, #SCI_INSERTTEXT, txtLen, MakeUTF8Text(Text$)) ; the problem is to measure the length of the text in Scintilla each time
					ScintillaSendMessage(0, #SCI_APPENDTEXT, TextLength, MakeScintillaText(Text$, @TextLength))
				Case 3
					; Text$ = "pasted text" ; before pasting it is brought to the UTF-8 format
					Text$ = GetClipboardText()
					ScintillaSendMessage(0, #SCI_APPENDTEXT, TextLength, MakeScintillaText(Text$, @TextLength))
				Case 4
					Break
				Case 5
					regex$ = "\d+"
					Color(MakeScintillaText(regex$, @TextLength), Len(regex$), 7)
				Case 6
					regex$ = "\d+"
					Color2(MakeScintillaText(regex$, @TextLength), Len(regex$), 7)
				Case 7
					ScintillaSendMessage(0, #SCI_CLEARDOCUMENTSTYLE)
			EndSelect
		Case #PB_Event_CloseWindow
			Break



EndSelect
ForEver

FreeMenu(0)
CloseWindow(100)
End

; Notifications
ProcedureDLL SciNotification(Gadget, *scinotify.SCNotification)
	Protected Path$, pos
; Select Gadget
; Case 0 ; Notify Gadget 0 (Scintilla)
	With *scinotify
		Select \nmhdr\code
			Case #SCN_URIDROPPED ; throw files in window
; Debug PeekS(*scinotify.SCNotification\text, -1, #PB_Ascii)
				Path$ = PeekS(*scinotify.SCNotification\text, -1, #PB_UTF8 | #PB_ByteLength)
Path$ = PeekS(*scinotify.SCNotification\text, -1, #PB_Ascii)
				pos = FindString(Path$, Chr(10)) ; trimming, leaving 1 file
				If pos
					Path$ = LSet(Path$ , pos-2)
				EndIf
				Path$ = RemoveString(Path$ , "file://", #PB_String_CaseSensitive, 1, 1) ; delete 1 time
				Debug Path$
				ReadFileR(Path$)
		EndSelect
	EndWith
; EndSelect
EndProcedure


; Convert text to text and paste into Scintilla
Procedure MakeUTF8Text(text.s)
	Static buffer.s
	buffer=Space(StringByteLength(text, #PB_UTF8))
	PokeS(@buffer, text, -1, #PB_UTF8)
	ProcedureReturn @buffer
EndProcedure

Procedure MakeScintillaText(text.s, *sciLength.Integer=0)
	Static sciLength : sciLength=StringByteLength(text, #PB_UTF8) ; #TextEncoding
	Static sciText.s : sciText = Space(sciLength)
	If *sciLength : *sciLength\i=sciLength : EndIf ;<--- Returns the length of the scintilla buffer (required for a specific scintilla command)
	PokeS(@sciText, text, -1, #PB_UTF8) ;--- #TextEncoding
	ProcedureReturn @sciText
EndProcedure

Procedure OpenFileR(*sciLength.Integer=0)
	; File path request
	Protected Path$ = OpenFileRequester("Select file","", "Text|*.txt;*.bat;*.pb|All files (*.*)|*.*",0)
	If Path$ ; since sciLength = 0 this is the override criterion for the following function
		ReadFileR(Path$)
	EndIf
EndProcedure

Procedure ReadFileR1(Path$) ; I replaced my own variant with the variant from the reference below
	Protected sizefile, *MemoryBuffer
	sizefile = FileSize(Path$) ; determine the data size in bytes
	If sizefile => 0 ; file exists
		*MemoryBuffer = AllocateMemory(sizefile) ; allocation of memory for the file size
		ReadFile(0 , Path$, #PB_UTF8)
		ReadData(0, *MemoryBuffer, sizefile) ; read file into memory
		CloseFile(0) ; close file
		ScintillaSendMessage(0, #SCI_SETTEXT, 0, *MemoryBuffer)
		ScintillaSendMessage(0, #SCN_UPDATEUI, #SC_UPDATE_V_SCROLL) ; not true, scroll update
		FreeMemory(*MemoryBuffer)
	EndIf
EndProcedure

Procedure ReadFileR(Path$)
	Protected length, *MemoryID
    If ReadFile(0, Path$)
        length = Lof(0) ; get length of the opened file
        *MemoryID = AllocateMemory(length) ; allocate necessary memory
        If *MemoryID
            ReadData(0, *MemoryID, length) ; read all data in the memory block
        EndIf
        CloseFile(0)
		ScintillaSendMessage(0, #SCI_SETTEXT, 0, *MemoryID)
		FreeMemory(*MemoryID)
    EndIf
EndProcedure

; highlighting through the indicators
Procedure Color(*regex, regexLength, n)
	Protected txtLen, StartPos, EndPos, firstMatchPos

	; Sets search mode (REGEX + POSIX braces)
	ScintillaSendMessage(0, #SCI_SETSEARCHFLAGS, #SCFIND_REGEXP | #SCFIND_POSIX)

	; Sets target search range
	txtLen = ScintillaSendMessage(0, #SCI_GETTEXTLENGTH) ; gets the text length
	ScintillaSendMessage(0, #SCI_INDICSETSTYLE, n, 6) ; #INDIC_TEXTFORE = 17 creates an indicator with number 7 (occupied by default 0, 1, 2)
	ScintillaSendMessage(0, #SCI_INDICSETFORE, n, $71AE71) ; assign colour of indicator number 7 - green

	EndPos = 0
	Repeat
		ScintillaSendMessage(0, #SCI_SETTARGETSTART, EndPos) ; from the beginning (set the search area) using the position of the previous search end
		ScintillaSendMessage(0, #SCI_SETTARGETEND, txtLen) ; to the end by the text length
		firstMatchPos=ScintillaSendMessage(0, #SCI_SEARCHINTARGET, regexLength, *regex) ; returns the position of the first found. The parameters are length and pointer
		If firstMatchPos>-1 ; if greater than -1, that is found
			StartPos=ScintillaSendMessage(0, #SCI_GETTARGETSTART) ; it gets position of the first found
			EndPos=ScintillaSendMessage(0, #SCI_GETTARGETEND) ; gets position of the end of found
			ScintillaSendMessage(0, #SCI_SETINDICATORCURRENT, n) ; makes the indicator number 7 current
			ScintillaSendMessage(0, #SCI_INDICATORFILLRANGE, StartPos, EndPos - StartPos) ; it selects text using the current indicator
		Else
			Break
		EndIf
	ForEver
EndProcedure

; highlighting via style
Procedure Color2(*regex, regexLength, n)
	Protected txtLen, StartPos, EndPos, firstMatchPos

	; Sets search mode (REGEX + POSIX curly brackets)
	ScintillaSendMessage(0, #SCI_SETSEARCHFLAGS, #SCFIND_REGEXP | #SCFIND_POSIX)

	; Sets target search range
	txtLen = ScintillaSendMessage(0, #SCI_GETTEXTLENGTH) ; gets the text length

	EndPos = 0
	Repeat
		ScintillaSendMessage(0, #SCI_SETTARGETSTART, EndPos) ; from the beginning (set the search area) using the position of the previous search end
		ScintillaSendMessage(0, #SCI_SETTARGETEND, txtLen) ; to the end by the text length
		firstMatchPos=ScintillaSendMessage(0, #SCI_SEARCHINTARGET, regexLength, *regex) ; returns the position of the first found. The parameters are length and pointer
		If firstMatchPos>-1 ; if greater than -1, that is found
			StartPos=ScintillaSendMessage(0, #SCI_GETTARGETSTART) ; it gets position of the first found
			EndPos=ScintillaSendMessage(0, #SCI_GETTARGETEND) ; gets position of the end of found
			ScintillaSendMessage(0, #SCI_STARTSTYLING, StartPos, 0) ; the start position (from the 50th)
			ScintillaSendMessage(0, #SCI_SETSTYLING, EndPos - StartPos, #LexerState_Number) ; width and style number
		Else
			Break
		EndIf
	ForEver
EndProcedure
Please ask your questions, because switch on the cognition apparatus decides on the only known life in the universe.Wersten :DDüsseldorf NRW Germany Europe Earth Solar System Flake Bubble Orionarm
Milky Way Local_Group Virgo Supercluster Laniakea Universe
infratec
Always Here
Always Here
Posts: 7666
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Editor Gadget

Post by infratec »

Best place for Scintilla informations:

https://www.scintilla.org/ScintillaDoc.html
AZJIO
Addict
Addict
Posts: 2230
Joined: Sun May 14, 2017 1:48 am

Re: Editor Gadget

Post by AZJIO »

juergenkulow wrote:@AZJIO,
can you please give some information about constants in your source code:
The link has already been given to you, I can only add links to ready-made examples
Post Reply