show typewriter input as disabled if non-primary goal is selected

pull/120/head
Jon Eugster 3 years ago committed by joneugster
parent 24eed37f89
commit b2936e0200

@ -51,6 +51,22 @@
/* margin: 0.2em 0 0; */ /* margin: 0.2em 0 0; */
} }
.typewriter.disabled{
background: #bbb;
}
.typewriter.disabled .btn-inverted,
.typewriter.disabled .mtk1 {
color: #777;
}
.typewriter.disabled .typewriter-input-wrapper,
.typewriter.disabled .monaco-editor,
.typewriter.disabled .monaco-editor-background,
.typewriter.disabled .btn-inverted {
background-color: #eee;
}
.typewriter form { .typewriter form {
display: flex; display: flex;
} }

@ -261,16 +261,15 @@ function Command({ command, deleteProof }: { command: string, deleteProof: any }
// }, fastIsEqual) // }, fastIsEqual)
/** The tabs of goals that lean ahs after the command of this step has been processed */ /** The tabs of goals that lean ahs after the command of this step has been processed */
function GoalsTabs({ proofStep, last, onClick}: { proofStep: ProofStep, last : boolean, onClick? : any }) { function GoalsTabs({ proofStep, last, onClick, onGoalChange=(n)=>{}}: { proofStep: ProofStep, last : boolean, onClick? : any, onGoalChange?: (n?: number) => void }) {
const [selectedGoal, setSelectedGoal] = React.useState<number>(0)
if (!proofStep.goals.length) { return <></> } const [selectedGoal, setSelectedGoal] = React.useState<number>(0)
return <div className="goal-tabs" onClick={onClick}> return <div className="goal-tabs" onClick={onClick}>
<div className={`tab-bar ${last ? 'current' : ''}`}> <div className={`tab-bar ${last ? 'current' : ''}`}>
{proofStep.goals.map((goal, i) => ( {proofStep.goals.map((goal, i) => (
// TODO: Should not use index as key. // TODO: Should not use index as key.
<div key={`proof-goal-${i}`} className={`tab ${i == (selectedGoal) ? "active" : ""}`} onClick={(ev) => { setSelectedGoal(i); ev.stopPropagation() }}> <div key={`proof-goal-${i}`} className={`tab ${i == (selectedGoal) ? "active" : ""}`} onClick={(ev) => { onGoalChange(i); setSelectedGoal(i); ev.stopPropagation() }}>
{i ? `Goal ${i + 1}` : "Active Goal"} {i ? `Goal ${i + 1}` : "Active Goal"}
</div> </div>
))} ))}
@ -297,6 +296,8 @@ export function TypewriterInterface(props: { world: string, level: number, data:
const proofPanelRef = React.useRef<HTMLDivElement>(null) const proofPanelRef = React.useRef<HTMLDivElement>(null)
const [disableInput, setDisableInput] = React.useState<boolean>(false)
/** Delete all proof lines starting from a given line. /** Delete all proof lines starting from a given line.
* Note that the first line (i.e. deleting everything) is `1`! * Note that the first line (i.e. deleting everything) is `1`!
*/ */
@ -342,6 +343,11 @@ export function TypewriterInterface(props: { world: string, level: number, data:
} else { } else {
proofPanelRef.current?.scrollTo(0,0) proofPanelRef.current?.scrollTo(0,0)
} }
// also reenable the commandline when the proof changes
// BUG: If selecting 2nd goal on a intermediate proofstep and then delete proof to there,
// the commandline is not displaying disabled even though it should.
setDisableInput(false)
}, [proof]) }, [proof])
// Scroll to element if selection changes // Scroll to element if selection changes
@ -460,7 +466,7 @@ export function TypewriterInterface(props: { world: string, level: number, data:
} }
</> </>
} }
<GoalsTabs proofStep={step} last={i == proof.length - (lastStepErrors ? 2 : 1)} onClick={toggleSelectStep(i)}/> <GoalsTabs proofStep={step} last={i == proof.length - (lastStepErrors ? 2 : 1)} onClick={toggleSelectStep(i)} onGoalChange={i == proof.length - 1 - withErr ? (n) => setDisableInput(n > 0) : (n) => {}}/>
{/* Show a message that there are no goals left */} {/* Show a message that there are no goals left */}
{!step.goals.length && ( {!step.goals.length && (
<div className="message information"> <div className="message information">
@ -493,7 +499,7 @@ export function TypewriterInterface(props: { world: string, level: number, data:
} }
</div> </div>
</div> </div>
<Typewriter hidden={!withErr && proof[proof.length - 1]?.goals.length == 0}/> <Typewriter hidden={!withErr && proof[proof.length - 1]?.goals.length == 0} disabled={disableInput}/>
</RpcContext.Provider> </RpcContext.Provider>
</div> </div>
} }

@ -64,7 +64,7 @@ config.autoClosingPairs = config.autoClosingPairs.map(
monaco.languages.setLanguageConfiguration('lean4cmd', config); monaco.languages.setLanguageConfiguration('lean4cmd', config);
/** The input field */ /** The input field */
export function Typewriter({hidden}: {hidden?: boolean}) { export function Typewriter({hidden, disabled}: {hidden?: boolean, disabled?: boolean}) {
/** Reference to the hidden multi-line editor */ /** Reference to the hidden multi-line editor */
const editor = React.useContext(MonacoEditorContext) const editor = React.useContext(MonacoEditorContext)
@ -308,7 +308,7 @@ export function Typewriter({hidden}: {hidden?: boolean}) {
runCommand() runCommand()
} }
return <div className={`typewriter${hidden ? ' hidden' : ''}`}> return <div className={`typewriter${hidden ? ' hidden' : ''}${disabled ? ' disabled' : ''}`}>
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
<div className="typewriter-input-wrapper"> <div className="typewriter-input-wrapper">
<div ref={inputRef} className="typewriter-input" /> <div ref={inputRef} className="typewriter-input" />

@ -142,7 +142,7 @@ function ChatPanel({lastLevel}) {
<div ref={chatRef} className="chat"> <div ref={chatRef} className="chat">
{introText?.filter(t => t.trim()).map(((t, i) => {introText?.filter(t => t.trim()).map(((t, i) =>
<Hint key={`intro-p-${i}`} <Hint key={`intro-p-${i}`}
hint={{text: t, hidden: false}} step={0} selected={null} toggleSelection={undefined} /> hint={{text: t, hidden: false}} step={0} selected={selectedStep} toggleSelection={toggleSelection(0)} />
))} ))}
{proof.map((step, i) => { {proof.map((step, i) => {
// It the last step has errors, it will have the same hints // It the last step has errors, it will have the same hints

Loading…
Cancel
Save