From 1a444f30e9b91aaebafbe341c604f0d48777841b Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 3 Dec 2022 21:41:54 +1000 Subject: [PATCH] Fix formatting inside selection not being removed Regression introduced in #2017 while fixing another bug. Closes #2072 --- ts/editor/surround.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ts/editor/surround.ts b/ts/editor/surround.ts index 4dd2a68d6..a36a05a67 100644 --- a/ts/editor/surround.ts +++ b/ts/editor/surround.ts @@ -359,7 +359,13 @@ export class Surrounder { return false; } - const isSurrounded = isSurroundedInner( + // This is confusing: when nothing is selected, we only + // include currently-active buttons, as otherwise inactive + // buttons get toggled on. But when something is selected, + // we include everything, since we want to remove formatting + // that may be in part of the selection, but not at the start/end. + + const isSurrounded = !range.collapsed || isSurroundedInner( range, base, boolMatcher(format),