Skip to content

Commit c21dbab

Browse files
committed
Add validation rule
1 parent 4b00aff commit c21dbab

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Tool/Sources/WorkspaceSuggestionService/Filespace+SuggestionService.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public extension Filespace {
5757
return false
5858
}
5959

60-
let editingLine = lines[cursorPosition.line].dropLast(1) // dropping \n
60+
let editingLine = lines[cursorPosition.line].dropLast(1) // dropping line ending
6161
let suggestionLines = presentingSuggestion.text.split(whereSeparator: \.isNewline)
6262
let suggestionFirstLine = suggestionLines.first ?? ""
6363

@@ -102,6 +102,16 @@ public extension Filespace {
102102

103103
return ""
104104
}()
105+
106+
/// if the line will not change after accepting the suggestion
107+
if presentingSuggestion.range.isOneLine {
108+
#warning("TODO: Also handle the case where the suggestion doesn't start at character 0")
109+
if editingLine == suggestionFirstLine {
110+
reset()
111+
resetSnapshot()
112+
return false
113+
}
114+
}
105115

106116
// the line content doesn't match the suggestion
107117
if cursorPosition.character > 0,

0 commit comments

Comments
 (0)