Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX improvements for renaming tabs #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/components/repl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Repl: ReplProps = (props) => {
const { compiler, formatter, linter } = props;
let now: number;

const tabRefs = new Map<string, HTMLSpanElement>();
const tabRefs : HTMLDivElement[] = [];

const [error, setError] = createSignal('');
const [compiled, setCompiled] = createSignal('');
Expand Down Expand Up @@ -187,24 +187,29 @@ const Repl: ReplProps = (props) => {
{(tab, index) => (
<TabItem active={props.current === tab.name} class="mr-2">
<div
ref={(el) => tabRefs.set(tab.name, el)}
ref={(el) => tabRefs[index()] = el}
class="cursor-pointer select-none rounded border border-solid border-transparent py-2 px-3 transition focus:border-blue-600 focus:outline-none"
contentEditable={edit() == index()}
onBlur={(e) => {
setEdit(-1);
setCurrentName(e.currentTarget.textContent!);
if (e.currentTarget.textContent) {
setCurrentName(e.currentTarget.textContent);
} else {
e.currentTarget.textContent = tab.name;
}
}}
onKeyDown={(e) => {
if (e.code === 'Space') e.preventDefault();
if (e.code !== 'Enter') return;
setEdit(-1);
setCurrentName(e.currentTarget.textContent!);
if (e.code !== 'Enter' && e.code !== 'Escape') return;
e.currentTarget.blur();
}}
onClick={() => setCurrentTab(tab.name)}
onDblClick={(e) => {
e.preventDefault();
setEdit(index());
tabRefs.get(tab.name)?.focus();
tabRefs[index()]?.focus();
// Fix for FireFox when editing the same tab twice
window.getSelection()?.setPosition(e.target, 0);
}}
>
{tab.name}
Expand Down