From d20aabdc8f1e633f0eaf63df51473e0d4ea111de Mon Sep 17 00:00:00 2001 From: Tom Beckmann Date: Sun, 24 Sep 2023 12:29:51 +0200 Subject: [PATCH] dc: keep empty lines --- packages/DomainCode-Parser/DCBlock.class.st | 16 ++++++++-- .../DCPairCompleteTest.class.st | 12 +++++++ .../DomainCode-Parser/DCParseTest.class.st | 31 +++++++++++++++++++ packages/DomainCode-Parser/DCUnknown.class.st | 6 ++++ .../SBTSCursorRaw.class.st | 17 ++++++++++ 5 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 packages/DomainCode-Parser/DCParseTest.class.st diff --git a/packages/DomainCode-Parser/DCBlock.class.st b/packages/DomainCode-Parser/DCBlock.class.st index d656243..4df95c7 100644 --- a/packages/DomainCode-Parser/DCBlock.class.st +++ b/packages/DomainCode-Parser/DCBlock.class.st @@ -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 | @@ -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 ] @@ -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]. @@ -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 [ diff --git a/packages/DomainCode-Parser/DCPairCompleteTest.class.st b/packages/DomainCode-Parser/DCPairCompleteTest.class.st index 25e3284..92a8c34 100644 --- a/packages/DomainCode-Parser/DCPairCompleteTest.class.st +++ b/packages/DomainCode-Parser/DCPairCompleteTest.class.st @@ -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 [ diff --git a/packages/DomainCode-Parser/DCParseTest.class.st b/packages/DomainCode-Parser/DCParseTest.class.st new file mode 100644 index 0000000..e74ff36 --- /dev/null +++ b/packages/DomainCode-Parser/DCParseTest.class.st @@ -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 +] diff --git a/packages/DomainCode-Parser/DCUnknown.class.st b/packages/DomainCode-Parser/DCUnknown.class.st index 9b5a47b..ed20797 100644 --- a/packages/DomainCode-Parser/DCUnknown.class.st +++ b/packages/DomainCode-Parser/DCUnknown.class.st @@ -15,3 +15,9 @@ DCUnknown >> initialize [ contents: ''; range: SBTSRange null) ] + +{ #category : #'as yet unclassified' } +DCUnknown >> prefersNoBorder [ + + ^ true +] diff --git a/packages/Sandblocks-TreeSitter/SBTSCursorRaw.class.st b/packages/Sandblocks-TreeSitter/SBTSCursorRaw.class.st index 52a5f66..7c8edf2 100644 --- a/packages/Sandblocks-TreeSitter/SBTSCursorRaw.class.st +++ b/packages/Sandblocks-TreeSitter/SBTSCursorRaw.class.st @@ -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 [