Page 1 of 1

Scintilla: multi-cursors editing like eclipse / sublimetext

Posted: Sun Nov 09, 2014 7:10 pm
by eddy
  • ALT+mouse selection : create rectangle selection
  • CTRL+mouse selection : create multi ranges selection
  • CTRL+mouse click : create additional cursor
  • CTRL+D: extend current selection ** TODO **
  • paste on multi selection
  • cursor move in virtual space (beyond end of lines)
Image

Code: Select all

EnableExplicit
InitScintilla()

#MENU_EXTEND_SELECTION=10
Define txt$, txtLen, marginWidth

Procedure MakeUTF8Text(text.s)
   Static buffer.s
   buffer=Space(StringByteLength(text, #PB_UTF8))
   PokeS(@buffer, text, -1, #PB_UTF8)
   ProcedureReturn @buffer
EndProcedure

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$="Scintilla is a free source code editing component. It comes with "+#CR$+
     "complete source code and a license that permits use in any project "+#CR$+
     "or product personal or commercial. The license may be viewed here. "+#CR$+
     "The source code, as well as the library documentation may be found "+#CR$+
     "on the Scintilla Homepage. From the Scintilla Homepage : As well As "+#CR$+
     "features found in standard text editing components, Scintilla includes "+#CR$+
     "features especially useful when editing And debugging source code."+#CR$+
     "These include support For syntax styling, error indicators, code "+#CR$+
     "completion And call tips.The selection margin can contain markers "+#CR$+
     "like those used in debuggers To indicate breakpoints and the current "+#CR$+
     "line.Styling choices are more open than With many editors, allowing the"+#CR$+
     " use of proportional fonts, bold And italics, multiple foreground "+#CR$+
     "and background colors And multiple fonts."+#CR$
txtLen=StringByteLength(txt$, #PB_UTF8)

OpenWindow(100, 0, 0, 600, 400, "Editing with Multi cursor (like eclipse or sublimetext)", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ScintillaGadget(0, 0, 0, WindowWidth(100), WindowHeight(100), 0)
; Set Text Mode
ScintillaSendMessage(0, #SCI_SETWRAPMODE, #SC_WRAP_NONE)
ScintillaSendMessage(0, #SCI_SETCODEPAGE, #SC_CP_UTF8)
ScintillaSendMessage(0, #SCI_SETVIRTUALSPACEOPTIONS, #SCVS_RECTANGULARSELECTION | #SCVS_USERACCESSIBLE) ; allow cursor and rect selection to move beyond end of line
; Set Current Line Highlighting
ScintillaSendMessage(0, #SCI_SETCARETLINEVISIBLE, 1)
ScintillaSendMessage(0, #SCI_SETCARETLINEVISIBLEALWAYS, 1)
ScintillaSendMessage(0, #SCI_SETCARETLINEBACKALPHA, 50)
ScintillaSendMessage(0, #SCI_SETCARETLINEBACK, RGB(100, 252, 195))
; Set Text style
ScintillaSendMessage(0, #SCI_STYLESETFONT, #STYLE_DEFAULT, MakeUTF8Text("Courier New")) ; rectangle selection works better with mono-width font
ScintillaSendMessage(0, #SCI_STYLESETBACK, #STYLE_DEFAULT, RGB(70, 78, 85))
ScintillaSendMessage(0, #SCI_STYLESETFORE, #STYLE_DEFAULT, RGB(195, 213, 255))
ScintillaSendMessage(0, #SCI_STYLECLEARALL)
; Set Margin size and style
ScintillaSendMessage(0, #SCI_STYLESETFONT, #STYLE_LINENUMBER, MakeUTF8Text("Arial"))
ScintillaSendMessage(0, #SCI_STYLESETBACK, #STYLE_LINENUMBER, RGB(53, 55, 57))
ScintillaSendMessage(0, #SCI_STYLESETFORE, #STYLE_LINENUMBER, RGB(200, 200, 200))
marginWidth=ScintillaSendMessage(0, #SCI_TEXTWIDTH, #STYLE_LINENUMBER, MakeUTF8Text("_999"))
ScintillaSendMessage(0, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)
ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 0, marginWidth)
marginWidth=0
ScintillaSendMessage(0, #SCI_SETMARGINMASKN, 2, #SC_MASK_FOLDERS)
ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 2, marginWidth)
ScintillaSendMessage(0, #SCI_SETMARGINSENSITIVEN, 2, #True)
; Set Main Caret and Selection
ScintillaSendMessage(0, #SCI_SETCARETSTICKY, 1) ;make always visible
ScintillaSendMessage(0, #SCI_SETCARETWIDTH, 3)  ;make thicker
ScintillaSendMessage(0, #SCI_SETCARETFORE, RGB(255, 160, 136))
ScintillaSendMessage(0, #SCI_SETSELALPHA, 100)
ScintillaSendMessage(0, #SCI_SETSELBACK, 1, RGB(255, 160, 136))
ScintillaSendMessage(0, #SCI_SETSELFORE, 1, RGB(200, 200, 200))
; Set Additional Caret and Selection
ScintillaSendMessage(0, #SCI_SETADDITIONALCARETFORE, RGB(157, 64, 41))
ScintillaSendMessage(0, #SCI_SETADDITIONALCARETSBLINK, 1)
ScintillaSendMessage(0, #SCI_SETADDITIONALSELALPHA, 100)
ScintillaSendMessage(0, #SCI_SETADDITIONALSELBACK, RGB(255, 160, 136))
ScintillaSendMessage(0, #SCI_SETADDITIONALSELFORE, RGB(200, 200, 200))
; Enable multi cursor editing
ScintillaSendMessage(0, #SCI_SETRECTANGULARSELECTIONMODIFIER, #SCMOD_ALT) ; select rectangle range by holding down the ALT key while dragging with the mouse
ScintillaSendMessage(0, #SCI_SETMULTIPLESELECTION, 1)                     ; select multiple ranges by holding down the CTRL or CMD key while dragging with the mouse
ScintillaSendMessage(0, #SCI_SETMULTIPASTE, #SC_MULTIPASTE_EACH)
ScintillaSendMessage(0, #SCI_SETADDITIONALSELECTIONTYPING, 1)
; Enable hotkey for selection auto extension CTRL + D
AddKeyboardShortcut(100, #PB_Shortcut_Control | #PB_Shortcut_D, #MENU_EXTEND_SELECTION)
BindEvent(#PB_Event_Menu, ExtendScintillaSelection())

; Change text
ScintillaSendMessage(0, #SCI_SETTEXT, 0, MakeUTF8Text(txt$))
ScintillaSendMessage(0, #SCI_GOTOPOS, txtLen)
SetActiveGadget(0)

Repeat: Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: Scintilla: multi-cursors editing like eclipse / sublimet

Posted: Sun Nov 09, 2014 8:43 pm
by davido
@eddy

Thank you for the demo. Very nice. :D

Re: Scintilla: multi-cursors editing like eclipse / sublimet

Posted: Mon Nov 10, 2014 2:15 am
by IdeasVacuum
Excellent stuff 8)

Re: Scintilla: multi-cursors editing like eclipse / sublimet

Posted: Mon Nov 10, 2014 9:34 pm
by Vera
Thank you for sharing :D

... allowed me to learn some more ~ V ~

Re: Scintilla: multi-cursors editing like eclipse / sublimet

Posted: Tue Nov 11, 2014 5:14 am
by fsw
Very nice, especially the choice of the colors.

BTW:
Every time I use SublimeText I wonder how they created the MiniMap.
Can't see a lag or smearing when using the MiniMap to scroll the code...

Re: Scintilla: multi-cursors editing like eclipse / sublimet

Posted: Sun Apr 01, 2018 7:21 pm
by Mistrel
Is there any way to get Ctrl-D support like SublimeText working with the PureBasic IDE? I actually find myself copy/pasting chunks of code back and forth into SublimeText to use this feature and it still ends up being faster than doing it all manually straight up in the IDE.

Re: Scintilla: multi-cursors editing like eclipse / sublimet

Posted: Mon Apr 02, 2018 3:49 pm
by Kwai chang caine
Very nice and works great, thanks for sharing 8)

Re: Scintilla: multi-cursors editing like eclipse / sublimet

Posted: Mon Apr 02, 2018 4:26 pm
by Kiffi
It's a pity that the PureBasic IDE still doesn't support this useful function after such a long time...

Re: Scintilla: multi-cursors editing like eclipse / sublimet

Posted: Mon Apr 02, 2018 5:25 pm
by Marc56us
Notepad++ does it too (and is freeware)

Re: Scintilla: multi-cursors editing like eclipse / sublimet

Posted: Thu Jul 19, 2018 9:54 am
by Mistrel
Following up on this. Multiple selection is the most missed feature I have moving between Sublime and PureBasic IDE.

Fun fact: searching for "scintilla multiple cursors" on Google lists this thread as the fourth result.