From ba1938e2f7455fba8d836b6558bb2dae7d827252 Mon Sep 17 00:00:00 2001 From: Michael Byrne Date: Thu, 10 Aug 2023 16:54:50 +1000 Subject: [PATCH] Fix tab to spaces replacement logic (#375) The existing implementation of converting a tab into spaces inadvertently includes an off-by-one error, producing one less space than desired. Fixes https://github.com/google/playground-elements/issues/358 --- CHANGELOG.md | 4 ++++ src/playground-code-editor.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffc74158..460f0b0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Fixed + +- Fix tab-to-spaces conversion in the code editor which was resulting in one less space being produced on tab than desired. + ## [0.18.0] - 2023-05-25 ### Changed diff --git a/src/playground-code-editor.ts b/src/playground-code-editor.ts index 74873047..4010e076 100644 --- a/src/playground-code-editor.ts +++ b/src/playground-code-editor.ts @@ -478,7 +478,7 @@ export class PlaygroundCodeEditor extends LitElement { extraKeys: { Tab: () => { cm.replaceSelection( - Array(cm.getOption('indentUnit') ?? 2).join(' ') + Array((cm.getOption('indentUnit') ?? 2) + 1).join(' ') ); }, // Ctrl + Space requests code completions.