Last active
October 2, 2025 18:11
-
-
Save banagale/cad99e29504466d825032a561aac2c59 to your computer and use it in GitHub Desktop.
Restore native Shift+Arrow text selection behavior in ChatGPT message editors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Natural Selection - Console Test Snippet - Extension here: https://github.com/banagale/natural-selection | |
| // Restores native Shift+Arrow text selection in ChatGPT editors | |
| (() => { | |
| 'use strict'; | |
| let guardUntil = 0; | |
| const arm = (ms) => guardUntil = performance.now() + ms; | |
| const active = () => performance.now() < guardUntil; | |
| let currentEditor = null; | |
| const isTypingEl = (el) => { | |
| if (!el) return false; | |
| return ( | |
| el.tagName === 'TEXTAREA' || | |
| el.tagName === 'INPUT' || | |
| el.isContentEditable || | |
| el.getAttribute?.('role') === 'textbox' | |
| ); | |
| }; | |
| window.addEventListener('keydown', (e) => { | |
| if (e.shiftKey && (e.key === 'ArrowUp' || e.key === 'ArrowDown')) { | |
| currentEditor = isTypingEl(e.target) | |
| ? e.target | |
| : e.target.closest?.('[contenteditable="true"], textarea, [role="textbox"]'); | |
| if (currentEditor) { | |
| e.stopImmediatePropagation(); | |
| console.log(`✓ Blocked ChatGPT's Shift+${e.key} handler`); | |
| } | |
| arm(400); | |
| } | |
| }, true); | |
| window.addEventListener('keyup', (e) => { | |
| if (e.shiftKey && (e.key === 'ArrowUp' || e.key === 'ArrowDown')) { | |
| const editor = isTypingEl(e.target) | |
| ? e.target | |
| : e.target.closest?.('[contenteditable="true"], textarea, [role="textbox"]'); | |
| if (editor) { | |
| e.stopImmediatePropagation(); | |
| } | |
| } | |
| if (e.key === 'ArrowUp' || e.key === 'ArrowDown') { | |
| arm(350); | |
| requestAnimationFrame(() => arm(150)); | |
| } | |
| }, true); | |
| const origScrollIntoView = Element.prototype.scrollIntoView; | |
| Element.prototype.scrollIntoView = function(...args) { | |
| if (active() && this.tagName === 'ARTICLE') { | |
| console.log('✓ Blocked unwanted scroll'); | |
| return; | |
| } | |
| return origScrollIntoView.apply(this, args); | |
| }; | |
| const origFocus = HTMLElement.prototype.focus; | |
| HTMLElement.prototype.focus = function(...args) { | |
| if (active() && currentEditor) { | |
| if (this !== currentEditor && !currentEditor.contains(this) && !this.contains(currentEditor)) { | |
| console.log('✓ Blocked focus theft'); | |
| return; | |
| } | |
| } | |
| return origFocus.apply(this, args); | |
| }; | |
| console.log('✓ Natural Selection loaded! Try Shift+Arrow text selection now.'); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment