TextEditor.CloseStrings is a new property that tells if strings should be automatically closed.

[GB.FORM.EDITOR]
* NEW: TextEditor.CloseStrings is a new property that tells if strings should be automatically closed.
This commit is contained in:
gambas 2018-12-11 02:18:38 +01:00
parent 43350ebfbd
commit eb36e0e17a
3 changed files with 107 additions and 59 deletions

View file

@ -15,6 +15,7 @@ Property DisabledBreakpoints As Integer[]
Property Bookmarks As Integer[]
Property EndOfLine As Integer
Property CloseBraces As Boolean
Property CloseStrings As Boolean
Public Lines As String[]
Public LinesInfo As CLineInfo[]
@ -39,6 +40,7 @@ Private $iBegin As Integer
Public _Mode As TextEditorMode
Private $sMode As String
Private $bCloseBraces As Boolean
Private $bCloseStrings As Boolean
Private $iEndOfLine As Integer = gb.Unix
Private $sEndOfLine As String = "\n"
@ -1589,6 +1591,7 @@ Private Sub Mode_Write(Value As String)
Highlight_Write(Value)
_Mode.CloseBraces = $bCloseBraces
_Mode.CloseStrings = $bCloseStrings
$sMode = Value
End
@ -1672,3 +1675,16 @@ Private Sub RaiseChange()
Next
End
Private Function CloseStrings_Read() As Boolean
Return $bCloseStrings
End
Private Sub CloseStrings_Write(Value As Boolean)
$bCloseStrings = Value
_Mode.CloseStrings = Value
End

View file

@ -4,7 +4,7 @@ Export
Inherits UserControl
Public Const _Properties As String = "*,Border=True,ShowPreview,ScrollBar{Scroll.*}=Both,Highlight{None;Custom;Gambas;HTML;CSS;WebPage;Diff;JavaScript;SQL}=None,Mode{None;Gambas;HTML;CSS;WebPage;JavaScript;SQL}=None,ReadOnly,TabSize{Range:2;64}=2,TabIndent,Wrap,ShowPosition,ShowLimit,ShowCurrent,ShowLineNumber,ShowModified,ShowBraces,ShowIcon,ShowExpand,ShowCursor=True,ShowSpaces,ShowIndent,CloseBraces"
Public Const _Properties As String = "*,Border=True,ShowPreview,ScrollBar{Scroll.*}=Both,Highlight{None;Custom;Gambas;HTML;CSS;WebPage;Diff;JavaScript;SQL}=None,Mode{None;Gambas;HTML;CSS;WebPage;JavaScript;SQL}=None,ReadOnly,TabSize{Range:2;64}=2,TabIndent,Wrap,ShowPosition,ShowLimit,ShowCurrent,ShowLineNumber,ShowModified,ShowBraces,ShowIcon,ShowExpand,ShowCursor=True,ShowSpaces,ShowIndent,CloseBraces,CloseStrings"
Public Const _DrawWith As String = "-"
Public Const _DefaultEvent As String = "Change"
Public Const _Similar As String = "TextArea"
@ -67,6 +67,7 @@ Property ShowExpand As Boolean
Property ShowSpaces As Boolean
Property ShowIndent As Boolean
Property CloseBraces As Boolean
Property CloseStrings As Boolean
Private Const MATCH_STRING As String = "()[]{}"
@ -5689,3 +5690,15 @@ Private Function LastColumn_Read() As Integer
Return $LX
End
Private Function CloseStrings_Read() As Boolean
Return $hDoc.CloseStrings
End
Private Sub CloseStrings_Write(Value As Boolean)
$hDoc.CloseStrings = Value
End

View file

@ -8,6 +8,7 @@ Static Public Const STRING_DELIM As String = "\""
Static Public Const ESCAPE_CHAR As String = "\\"
Public CloseBraces As Boolean
Public CloseStrings As Boolean
Public InsideStringEscape As Boolean
Static Public Sub _init()
@ -146,12 +147,13 @@ Public Sub OnKeyPress(hEditor As TextEditor) As Boolean
Dim sCar As String
Dim iPos As Integer
Dim sText As String
Dim sSearch As String
sText = Key.Text
If Key.Code = Key.BackSpace Then
If Not CloseBraces Then Return
If Not CloseBraces And If Not CloseStrings Then Return
If hEditor.Selected Then Return
@ -160,11 +162,20 @@ Public Sub OnKeyPress(hEditor As TextEditor) As Boolean
sLine = hEditor.Current.Text
sCar = String.Mid$(sLine, X, 1)
iPos = InStr(Me.BRACES_OPEN & Me.STRING_DELIM, sCar)
sSearch = ""
If CloseBraces Then sSearch = Me.BRACES_OPEN
If CloseStrings Then sSearch &= Me.STRING_DELIM
iPos = InStr(sSearch, sCar)
If iPos = 0 Then Return
sSearch = ""
If CloseBraces Then sSearch = Me.BRACES_CLOSE
If CloseStrings Then sSearch &= Me.STRING_DELIM
sCar = String.Mid$(sLine, X + 1, 1)
If sCar <> Mid$(Me.BRACES_CLOSE & Me.STRING_DELIM, iPos, 1) Then Return
If sCar <> Mid$(sSearch, iPos, 1) Then Return
hEditor.SaveCursor()
hEditor.Select(X - 1, hEditor.Line, X + 1, hEditor.Line)
@ -177,72 +188,80 @@ Public Sub OnKeyPress(hEditor As TextEditor) As Boolean
InsideStringEscape = False
iPos = InStr(Me.BRACES_OPEN, sText)
If iPos Then
If hEditor.Selected Then
If hEditor.SelectionLine = hEditor.Line Then
hEditor.Insert(sText & hEditor.SelectedText & Mid$(Me.BRACES_CLOSE, iPos, 1))
Return True
Endif
Endif
If CanCloseBraces(hEditor) Then
hEditor.Begin
hEditor.SaveCursor()
hEditor.Insert(sText)
hEditor.Insert(Mid$(Me.BRACES_CLOSE, iPos, 1))
hEditor.RestoreCursor()
hEditor.Goto(hEditor.Column + 1, hEditor.Line)
hEditor.End
'$bCanCloseBracesComputed = False
Return True
Endif
Return
Endif
If CloseBraces Then
iPos = InStr(Me.BRACES_CLOSE, sText)
If iPos Then
If String.Mid$(hEditor.Current.Text, hEditor.Column + 1, 1) = sText Then
hEditor.Goto(hEditor.Column + 1, hEditor.Line)
Return True
Endif
Return
Endif
iPos = InStr(Me.STRING_DELIM, sText)
If iPos Then
If Not InsideString(hEditor) Then
iPos = InStr(Me.BRACES_OPEN, sText)
If iPos Then
hEditor.SaveCursor()
hEditor.Insert(sText & sText)
hEditor.RestoreCursor()
hEditor.Goto(hEditor.Column + 1, hEditor.Line)
Return True
Else If hEditor.Column < hEditor.Current.Length Then
If Not InsideStringEscape Then
If String.Mid$(hEditor.Current.Text, hEditor.Column + 1, 1) = sText Then
hEditor.Goto(hEditor.Column + 1, hEditor.Line)
If hEditor.Selected Then
If hEditor.SelectionLine = hEditor.Line Then
hEditor.Insert(sText & hEditor.SelectedText & Mid$(Me.BRACES_CLOSE, iPos, 1))
Return True
Endif
Endif
If CanCloseBraces(hEditor) Then
hEditor.Begin
hEditor.SaveCursor()
hEditor.Insert(sText)
hEditor.Insert(Mid$(Me.BRACES_CLOSE, iPos, 1))
hEditor.RestoreCursor()
hEditor.Goto(hEditor.Column + 1, hEditor.Line)
hEditor.End
'$bCanCloseBracesComputed = False
Return True
Endif
Return
Endif
iPos = InStr(Me.BRACES_CLOSE, sText)
If iPos Then
If String.Mid$(hEditor.Current.Text, hEditor.Column + 1, 1) = sText Then
hEditor.Goto(hEditor.Column + 1, hEditor.Line)
Return True
Endif
Return
Endif
Endif
If CloseStrings Then
iPos = InStr(Me.STRING_DELIM, sText)
If iPos Then
If Not InsideString(hEditor) Then
hEditor.SaveCursor()
hEditor.Insert(sText & sText)
hEditor.RestoreCursor()
hEditor.Goto(hEditor.Column + 1, hEditor.Line)
Return True
Else If hEditor.Column < hEditor.Current.Length Then
If Not InsideStringEscape Then
If String.Mid$(hEditor.Current.Text, hEditor.Column + 1, 1) = sText Then
hEditor.Goto(hEditor.Column + 1, hEditor.Line)
Return True
Endif
hEditor.SaveCursor()
hEditor.Insert(sText & sText)
hEditor.RestoreCursor()
hEditor.Goto(hEditor.Column + 1, hEditor.Line)
Return True
Endif
Endif
Endif