Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implement some small performance improvements * implement further small perf improvements * fix linting * avoid Three.Vector3 creation, vector unpacking etc. for position updates * avoid some THREE.Vector3 instantiations and redundant set of scale * fix linting * only set position in updateCameraForScene * use nanoEvents for buckets instead of backbone events * avoid array allocation in TextureBucketManager * fix test * rework toolbar: use icons for tools; show current cell id in navbar etc. * reflect modifier change directly in toolbar * temporarily disable most CI checks * work on dynamic overwrite-mode in UI * refactor overwrite-cell mechanism * fix tests * fix test and restore CI * fix broken merge and some padding * fix useEffect toggle bug; also adapt active tool when pressing Alt * improve tooltips for tools and fix CSS issues with borders on hover * move hooks into own module * also show tooltips when pressing modifiers in move-tool; fix missing keyRelease-bug when leaving browser tab * fix that ctrl+right-click always re-centered the current node * remove unused idle enum * swap brush and trace-tool; make lasso.svg blue via css-filtering when being active * support dragging the plane via middle-click * update changelog * only re-render SaveButton if necessary (by explicitly passing progressFraction and by accessing the oldest unsaved timestamp ad-hoc) * fix cycling order of tools; update changelog * Apply suggestions from code review Co-authored-by: Daniel <daniel.werner@scalableminds.com> * remove duplicate from changelog * allow middle-drag-movement in all tracing modes; add more comments * fix border on hovering disabled radio button * respect mapping when rendering the current cell color in the new-cell-color-button * workaround modifier-release-bug and adapt merge-tree-message * satisfy linter Co-authored-by: Daniel <daniel.werner@scalableminds.com>
- Loading branch information
1 parent
0553f8e
commit aa959cd
Showing
27 changed files
with
661 additions
and
192 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// @flow | ||
import { useState, useEffect, useRef } from "react"; | ||
|
||
// Adapted from: https://usehooks.com/usePrevious/ | ||
export function usePrevious<T>(value: T): ?T { | ||
// The ref object is a generic container whose current property is mutable ... | ||
// ... and can hold any value, similar to an instance property on a class | ||
const ref = useRef<?T>(null); | ||
|
||
// Store current value in ref | ||
useEffect(() => { | ||
ref.current = value; | ||
}, [value]); // Only re-run if value changes | ||
|
||
// Return previous value (happens before update in useEffect above) | ||
return ref.current; | ||
} | ||
|
||
const extractModifierState = event => ({ | ||
Shift: event.shiftKey, | ||
Alt: event.altKey, | ||
Control: event.ctrlKey, | ||
}); | ||
|
||
// Adapted from: https://gist.github.com/gragland/b61b8f46114edbcf2a9e4bd5eb9f47f5 | ||
export function useKeyPress(targetKey: string) { | ||
// State for keeping track of whether key is pressed | ||
const [keyPressed, setKeyPressed] = useState(false); | ||
|
||
// If pressed key is our target key then set to true | ||
function downHandler(event) { | ||
const modifierState = extractModifierState(event); | ||
|
||
if (modifierState[targetKey] === undefined) { | ||
// The targetKey is not a modifier. Compare to the pressed key. | ||
if (event.key === targetKey) { | ||
pressKey(); | ||
} | ||
} else if (modifierState[targetKey]) { | ||
// Use the modifierState as this seems to be more robust. See | ||
// the other comment below which describes some edge cases | ||
// regarding modifiers. | ||
pressKey(); | ||
} | ||
} | ||
|
||
function pressKey() { | ||
setKeyPressed(true); | ||
window.addEventListener("blur", releaseKey); | ||
} | ||
|
||
function releaseKey() { | ||
setKeyPressed(false); | ||
window.removeEventListener("blur", releaseKey); | ||
} | ||
|
||
// If released key is our target key then set to false | ||
const upHandler = event => { | ||
const modifierState = extractModifierState(event); | ||
|
||
if (modifierState[targetKey] === undefined) { | ||
// The targetKey is not a modifier. Compare to the pressed key. | ||
if (event.key === targetKey) { | ||
releaseKey(); | ||
} | ||
} else if (!modifierState[targetKey]) { | ||
// The targetKey is a modifier. Use the modifierState as this | ||
// is more robust against pressing multiple modifiers. For example, | ||
// on Linux, pressing Shift and then toggling Alt, will send a release | ||
// of the Meta key even though that key was never touched. | ||
releaseKey(); | ||
} | ||
}; | ||
|
||
// Add event listeners | ||
useEffect(() => { | ||
window.addEventListener("keydown", downHandler); | ||
window.addEventListener("keyup", upHandler); | ||
// Remove event listeners on cleanup | ||
return () => { | ||
window.removeEventListener("keydown", downHandler); | ||
window.removeEventListener("keyup", upHandler); | ||
}; | ||
}, []); // Empty array ensures that effect is only run on mount and unmount | ||
|
||
return keyPressed; | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.