From c093eb5a383aa9ab10a4a84c83856a28fe5fef4f Mon Sep 17 00:00:00 2001 From: ishikawa999 <14245262+ishikawa999@users.noreply.github.com> Date: Tue, 9 Jun 2026 08:28:59 +0900 Subject: [PATCH 3/3] Fix Tab/Shift+Tab indenting the line after a trailing newline in selection --- .../controllers/selection_indent_controller.js | 3 ++- test/system/selection_indent_test.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/javascript/controllers/selection_indent_controller.js b/app/javascript/controllers/selection_indent_controller.js index e6555e7fe..007e94c0c 100644 --- a/app/javascript/controllers/selection_indent_controller.js +++ b/app/javascript/controllers/selection_indent_controller.js @@ -12,7 +12,8 @@ export default class extends Controller { const hasSelection = selectionStart !== selectionEnd if (!hasSelection) return const start = value.lastIndexOf("\n", selectionStart - 1) + 1 - const end = value.indexOf("\n", selectionEnd) + const adjustedSelectionEnd = value[selectionEnd - 1] === "\n" ? selectionEnd - 1 : selectionEnd + const end = value.indexOf("\n", adjustedSelectionEnd) const endPos = end === -1 ? value.length : end const selectedText = value.slice(start, endPos) const lines = selectedText.split("\n") diff --git a/test/system/selection_indent_test.rb b/test/system/selection_indent_test.rb index 62dc9269c..9e8fcfe21 100644 --- a/test/system/selection_indent_test.rb +++ b/test/system/selection_indent_test.rb @@ -68,6 +68,22 @@ class SelectionIndentSystemTest < ApplicationSystemTestCase end end + def test_tab_does_not_indent_line_after_trailing_newline_in_selection + with_settings :text_formatting => 'common_mark' do + visit '/projects/ecookbook/issues/new' + + within('form#issue-form') do + text = "line1\nline2\nline3" + el = find('#issue_description') + el.click + # Select "line1\n" — selection ends at the start of line2 + set_textarea_value 'issue_description', text, selection: [0, "line1\n".length] + el.send_keys(:tab) + assert_equal " line1\nline2\nline3", el.value + end + end + end + def test_shift_tab_unindents_selected_text with_settings :text_formatting => 'common_mark' do visit '/projects/ecookbook/issues/new' -- 2.54.0