Skip to content

Commit

Permalink
dc: keep empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
tom95 committed Sep 24, 2023
1 parent 085ddb9 commit d20aabd
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/DomainCode-Parser/DCBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ DCBlock class >> fromCursor: aCursor language: aLanguage [

aCursor gotoFirstChild
ifTrue: [
[node addMorphBack: (self fromCursor: aCursor language: aLanguage)] doWhileFalse: [aCursor gotoNextSibling].
[
aCursor numberOfNewLinesToNext - 1 timesRepeat: [node addMorphBack: (DCUnknown new language: aLanguage)].
node addMorphBack: (self fromCursor: aCursor language: aLanguage)] doWhileFalse: [aCursor gotoNextSibling].
aCursor gotoParent]
ifFalse: [
aCursor text ifNotEmpty: [:text |
Expand Down Expand Up @@ -96,7 +98,7 @@ DCBlock >> deleteBeforeCursor [
before contents: before contents, m contents.
m contents: '']
ifFalse: [before contents ifNotEmpty: [before contents: before contents allButLast]]]]
ifFalse: [m deleteBeforeCursor]]
ifFalse: [m contents ifEmpty: [self deleteBlock] ifNotEmpty: [m deleteBeforeCursor]]]
input: Character backspace asString
]

Expand Down Expand Up @@ -162,7 +164,9 @@ DCBlock >> handleInsertEvent: anEvent in: textMorph [
input := anEvent keyCharacter asString.
pairMap at: input ifPresent: [:complete |
"do not autocomplete quotes in words"
(textMorph contents notEmpty and: [complete = '''']) ifTrue: [^ textMorph insertString: input].
((textMorph characterBeforeCursor
ifNotNil: #isAlphaNumeric
ifNil: [false]) and: [complete = '''']) ifTrue: [^ textMorph insertString: input].

"do not autocomplete after backslash"
textMorph characterBeforeCursor = $\ ifTrue: [^ textMorph insertString: input].
Expand Down Expand Up @@ -282,6 +286,12 @@ DCBlock >> insertStatementAboveOrBelow: anAboveBoolean [
morph: (DCUnknown new language: self language))]
]

{ #category : #'as yet unclassified' }
DCBlock >> insertStatementHasCandidate [

^ true
]

{ #category : #'as yet unclassified' }
DCBlock >> isBlockBody [

Expand Down
12 changes: 12 additions & 0 deletions packages/DomainCode-Parser/DCPairCompleteTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ DCPairCompleteTest >> testDeleteInPair [
self assert: '' equals: editor childSandblocks first sourceString
]

{ #category : #'as yet unclassified' }
DCPairCompleteTest >> testDontSkipInsertQuoteAfterSpace [

| program editor |
program := DCBlock parse: 'a' language: SBJavascript.
editor := self editorAndWorldFor: program.
program lastDeepChild startInputAtEnd.
self type: ' ''' in: editor.
self assert: 'a
''''' equals: editor childSandblocks first sourceString
]

{ #category : #'as yet unclassified' }
DCPairCompleteTest >> testIgnoreAfterBackslash [

Expand Down
31 changes: 31 additions & 0 deletions packages/DomainCode-Parser/DCParseTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Class {
#name : #DCParseTest,
#superclass : #SBTest,
#category : #'DomainCode-Parser'
}

{ #category : #'as yet unclassified' }
DCParseTest >> testDeleteEmptyLine [

| program editor |
program := DCBlock parse: 'a;
b;' language: SBJavascript.
editor := self editorAndWorldFor: program.
program childSandblocks second startInputAtEnd.
editor handle: (self keyboardEvent: Character backspace).
self assert: 2 equals: editor childSandblocks first childSandblocks size
]

{ #category : #'as yet unclassified' }
DCParseTest >> testKeepEmptyLine [

| program editor |
program := DCBlock parse: 'a;
b;' language: SBJavascript.
editor := self editorAndWorldFor: program.
program lastDeepChild startInputAtEnd.
self type: 'b' in: editor.
self assert: 3 equals: editor childSandblocks first childSandblocks size
]
6 changes: 6 additions & 0 deletions packages/DomainCode-Parser/DCUnknown.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ DCUnknown >> initialize [
contents: '';
range: SBTSRange null)
]

{ #category : #'as yet unclassified' }
DCUnknown >> prefersNoBorder [

^ true
]
17 changes: 17 additions & 0 deletions packages/Sandblocks-TreeSitter/SBTSCursorRaw.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ SBTSCursorRaw >> node [
do: {[cursor currentNode]. [library cursorCurrentNode: cursor]}
]

{ #category : #'as yet unclassified' }
SBTSCursorRaw >> numberOfNewLinesToNext [

| current previous text |
self atEnd
ifTrue: [
current := nil.
previous := self node]
ifFalse: [
current := self node.
previous := self previousNode: current.
previous ifNil: [^ 0]].
self position > (self endByteIndex: previous) ifTrue: [^ 0].
text := self textBetween: previous and: current.
^ text occurrencesOf: Character lf
]

{ #category : #'as yet unclassified' }
SBTSCursorRaw >> parent [

Expand Down

0 comments on commit d20aabd

Please sign in to comment.