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),