diff --git a/src/typechecker.ts b/src/typechecker.ts
index 3ead85c9..b1237145 100644
--- a/src/typechecker.ts
+++ b/src/typechecker.ts
@@ -347,17 +347,19 @@ function previousText(expr: Expr, path: PathItem[]): string | null {
function textFromPreviousPart(seq: Seq, index: number): string | null {
let prevIndex = index - 1;
+ let text = null;
let prev;
while (isProsePart((prev = seq.items[prevIndex]))) {
if (prev.name === 'text') {
- return prev.contents;
+ text = prev.contents + (text ?? '');
+ --prevIndex;
} else if (prev.name === 'tag') {
--prevIndex;
} else {
break;
}
}
- return null;
+ return text;
}
function stripWhitespace(items: NonSeq[]) {
diff --git a/test/typecheck.js b/test/typecheck.js
index 71be5c5f..90d33cec 100644
--- a/test/typecheck.js
+++ b/test/typecheck.js
@@ -203,6 +203,8 @@ describe('typechecking completions', () => {
1. Set _a_ to Completion(ExampleAlg()).
1. Set _a_ to ! ExampleAlg().
1. Return ? ExampleAlg().
+ 1. Return ? ExampleAlg().
+ 1. Return ? ! ExampleAlg().
1. Let _foo_ be 0.
1. Set _a_ to Completion(ExampleSDO of _foo_).
1. Set _a_ to Completion(ExampleSDO of _foo_ with argument 0).
@@ -284,6 +286,7 @@ describe('typechecking completions', () => {
1. Return ExampleAlg().
+ 1. Return ! ExampleAlg().
`);