Scintilla: multi-cursors editing like eclipse / sublimetext

Share your advanced PureBasic knowledge/code with the community.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Scintilla: multi-cursors editing like eclipse / sublimetext

Post 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
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

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

Post by davido »

@eddy

Thank you for the demo. Very nice. :D
DE AA EB
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post by IdeasVacuum »

Excellent stuff 8)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

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

Post by Vera »

Thank you for sharing :D

... allowed me to learn some more ~ V ~
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

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

Post 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...

I am to provide the public with beneficial shocks.
Alfred Hitshock
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

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

Post 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.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

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

Post by Kwai chang caine »

Very nice and works great, thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
User avatar
Kiffi
Addict
Addict
Posts: 1353
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

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

Post by Kiffi »

It's a pity that the PureBasic IDE still doesn't support this useful function after such a long time...
Hygge
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

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

Post by Marc56us »

Notepad++ does it too (and is freeware)
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

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

Post 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.
Post Reply