From 0f7b45ab38e5c25cd145b96b2bd3c7d708baeea4 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 1 Jul 2025 12:15:02 +0200 Subject: [PATCH] Use lexical in the command line --- Gemfile | 2 +- Gemfile.lock | 13 ++++++------- app/assets/stylesheets/terminals.css | 16 ++++++++++++++++ .../controllers/terminal_controller.js | 15 +++++++++++---- app/views/commands/_form.html.erb | 9 ++++----- 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/Gemfile b/Gemfile index 2f56fa81d..1c6f1c8f7 100644 --- a/Gemfile +++ b/Gemfile @@ -27,7 +27,7 @@ gem "rqrcode" gem "redcarpet" gem "rouge" gem "jbuilder" -gem "actiontext-lexical", bc: "actiontext-lexical" +gem "actiontext-lexical", path: "/Users/jorge/Work/jorgemanrubia/actiontext-lexical" gem "image_processing", "~> 1.14" gem "platform_agent" gem "aws-sdk-s3", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 9c79b7482..4c88c72f4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,3 @@ -GIT - remote: https://github.com/basecamp/actiontext-lexical - revision: 8a2cede49ca51e40004a0f03100b3f189b60fdd8 - specs: - actiontext-lexical (0.1.0) - rails (>= 8.0.2) - GIT remote: https://github.com/basecamp/active_record-tenanted revision: 81a4d02a363fa749de517c90e19588365f934913 @@ -209,6 +202,12 @@ GIT thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) +PATH + remote: /Users/jorge/Work/jorgemanrubia/actiontext-lexical + specs: + actiontext-lexical (0.1.0) + rails (>= 8.0.2) + GEM remote: https://rubygems.org/ specs: diff --git a/app/assets/stylesheets/terminals.css b/app/assets/stylesheets/terminals.css index 58f1f3de6..eaafbb11f 100644 --- a/app/assets/stylesheets/terminals.css +++ b/app/assets/stylesheets/terminals.css @@ -122,6 +122,22 @@ caret-color: var(--color-negative); color: var(--color-negative); } + + .lexical-editor__content { + min-block-size: initial; + margin: 0; + + b, strong, i, em { + font-weight: inherit; + font-style: inherit; + } + + ul, li { + list-style: none; + margin: 0; + padding: 0; + } + } } .terminal__label { diff --git a/app/javascript/controllers/terminal_controller.js b/app/javascript/controllers/terminal_controller.js index 009a14fdf..efcd9b357 100644 --- a/app/javascript/controllers/terminal_controller.js +++ b/app/javascript/controllers/terminal_controller.js @@ -2,6 +2,7 @@ import { Controller } from "@hotwired/stimulus" import { HttpStatus } from "helpers/http_helpers" import { isMultiLineString } from "helpers/text_helpers"; import { marked } from "marked" +import { nextFrame } from "helpers/timing_helpers"; export default class extends Controller { static targets = [ "input", "form", "output", "confirmation", "recentCommands" ] @@ -14,9 +15,11 @@ export default class extends Controller { // Actions - focus() { - this.inputTarget.setSelectionRange(this.inputTarget.value.length, this.inputTarget.value.length) + async focus() { + await nextFrame() + this.inputTarget.focus() + this.inputTarget.selection.placeCursorAtTheEnd() } executeCommand(event) { @@ -38,6 +41,11 @@ export default class extends Controller { this.#hideOutput() } + submitCommand() { + this.formTarget.requestSubmit() + this.#reset() + } + handleKeyPress(event) { if (this.waitingForConfirmationValue) { this.#handleConfirmationKey(event.key.toLowerCase()) @@ -175,8 +183,7 @@ export default class extends Controller { this.inputTarget.value = this.originalInputValue this.confirmationTarget.value = "confirmed" this.#hideOutput() - this.formTarget.requestSubmit() - this.#reset() + this.submitCommand() } #showOutput(markdown) { diff --git a/app/views/commands/_form.html.erb b/app/views/commands/_form.html.erb index afd59d6a0..b675aedc4 100644 --- a/app/views/commands/_form.html.erb +++ b/app/views/commands/_form.html.erb @@ -8,14 +8,13 @@ } do %> - <%= text_field_tag "command", nil, - autocomplete: "off", - autocorrect: "off", - autocapitalize: "off", + <%= rich_textarea_tag "command", nil, + toolbar: false, class: "terminal__input input fill-transparent unpad", + "single-line": true, data: { terminal_target: "input", - action: "keydown.up->toggle-class#add:prevent keydown.up->navigable-list#selectCurrentOrReset:stop terminal#hideError" + action: "keydown.enter->terminal#submitCommand keydown.up->toggle-class#add:prevent keydown.up->navigable-list#selectCurrentOrReset:stop terminal#hideError" }, placeholder: platform.desktop? ? "Press #{ hotkey_label(["ctrl", "K"]) } to search or type commands…" : "Search or type commands…", spellcheck: "false" %>