Use shift instead of capslock for multiple line selection (#62)
Use shift instead of caplock for multiple line selection
This commit is contained in:
@ -153,7 +153,10 @@ function App() {
|
|||||||
>
|
>
|
||||||
format
|
format
|
||||||
</button> */}
|
</button> */}
|
||||||
<div className="bg-red h-full w-full overflow-auto">
|
<div
|
||||||
|
className="bg-red h-full w-full overflow-auto"
|
||||||
|
id="code-mirror-override"
|
||||||
|
>
|
||||||
<CodeMirror
|
<CodeMirror
|
||||||
className="h-full"
|
className="h-full"
|
||||||
value={code}
|
value={code}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
import { useStore } from '../useStore'
|
import { useStore } from '../useStore'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
|
|
||||||
|
// Kurt's note: codeMirror styling overrides were needed to make this work
|
||||||
|
// namely, the cursor needs to still be shown when the editor is not focused
|
||||||
|
// search for code-mirror-override in the repo to find the relevant styles
|
||||||
|
|
||||||
export function useHotKeyListener() {
|
export function useHotKeyListener() {
|
||||||
const { setIsShiftDown } = useStore((s) => ({
|
const { setIsShiftDown } = useStore((s) => ({
|
||||||
setIsShiftDown: s.setIsShiftDown,
|
setIsShiftDown: s.setIsShiftDown,
|
||||||
}))
|
}))
|
||||||
const keyName = 'CapsLock' // TODO #32 should be shift, but shift conflicts with the editor's use of the shift key atm.
|
const keyName = 'Shift'
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleKeyDown = (event: KeyboardEvent) =>
|
const handleKeyDown = (event: KeyboardEvent) =>
|
||||||
event.key === keyName && setIsShiftDown(true)
|
event.key === keyName && setIsShiftDown(true)
|
||||||
|
@ -11,9 +11,5 @@ export function useSetCursor(sourceRange: Range) {
|
|||||||
? [...selectionRanges, sourceRange]
|
? [...selectionRanges, sourceRange]
|
||||||
: [sourceRange]
|
: [sourceRange]
|
||||||
setCursor(ranges)
|
setCursor(ranges)
|
||||||
const element: HTMLDivElement | null = document.querySelector('.cm-content')
|
|
||||||
if (element) {
|
|
||||||
element.focus()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,3 +17,12 @@ code {
|
|||||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||||
monospace;
|
monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#code-mirror-override .cm-focused .cm-cursor {
|
||||||
|
border-left: 1.2px solid black;
|
||||||
|
}
|
||||||
|
#code-mirror-override .cm-cursor {
|
||||||
|
display: block;
|
||||||
|
border-left: 5px solid #0084e2;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user