1import { Controller } from "@hotwired/stimulus" 2 3// Copies text content from a source element to an input/textarea 4// Usage: 5// <div data-controller="copy-to-input"> 6// <input data-copy-to-input-target="input"> 7// <div data-copy-to-input-target="source">Text to copy</div> 8// <button data-action="copy-to-input#copy">Copy</button> 9// </div> 10export default class extends Controller { 11 static targets = ["input", "source"] 12 static values = { 13 feedbackText: { type: String, default: "Copied!" }, 14 feedbackDuration: { type: Number, default: 1500 } 15 } 16 17 copy(event) { 18 event.preventDefault() 19 20 const text = this.sourceTarget.textContent.trim() 21 this.inputTarget.value = text 22 this.inputTarget.dispatchEvent(new Event("input", { bubbles: true })) 23 24 this.#showFeedback(event.target) 25 } 26 27 #showFeedback(button) { 28 const originalText = button.textContent 29 button.style.width = `${button.offsetWidth}px` 30 button.textContent = this.feedbackTextValue 31 setTimeout(() => { 32 button.textContent = originalText 33 button.style.width = "" 34 }, this.feedbackDurationValue) 35 } 36}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.