Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions packages/cheatsheet-local/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"extends": "../../tsconfig.web.json",
"compilerOptions": {
"skipLibCheck": true
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
Expand Down
3 changes: 1 addition & 2 deletions packages/cheatsheet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"dependencies": {
"@cursorless/common": "workspace:*",
"preact": "^10.29.0",
"react-bootstrap-icons": "^1.11.6",
"react-use": "^17.6.0"
"react-bootstrap-icons": "^1.11.6"
},
"devDependencies": {
"@types/jest": "^30.0.0",
Expand Down
30 changes: 25 additions & 5 deletions packages/cheatsheet/src/lib/utils/useIsHighlighted.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useHash } from "react-use";
import { useCallback, useEffect, useState } from "preact/hooks";

// Check if window is defined (so if in the browser or in node.js).
const isBrowser = typeof window !== "undefined";
Expand All @@ -8,8 +8,28 @@ const isBrowser = typeof window !== "undefined";
* @param id The id to match the hash against
* @returns Boolean indicating whether the hash matches the given id
*/
export default function useIsHighlighted(id: string) {
const [hash, _] = isBrowser ? useHash() : ["", null];

return hash.length > 1 && hash.substring(1) === id;
export default function useIsHighlighted(id: string): boolean {
if (isBrowser) {
const hash = useHash();
return hash === `#${id}`;
}
return false;
}

const useHash = () => {
const [hash, setHash] = useState(() => window.location.hash);
Comment thread
AndreasArvidsson marked this conversation as resolved.

const onHashChange = useCallback(() => {
setHash(window.location.hash);
}, []);

useEffect(() => {
window.addEventListener("hashchange", onHashChange);

return () => {
window.removeEventListener("hashchange", onHashChange);
};
}, []);

return hash;
};
3 changes: 0 additions & 3 deletions packages/cheatsheet/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"extends": "../../tsconfig.web.json",
"compilerOptions": {
"skipLibCheck": true
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
Expand Down
6 changes: 1 addition & 5 deletions packages/cursorless-org/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"extends": "../../tsconfig.web.json",
"compilerOptions": {
"skipLibCheck": true
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.json",
"../../typings/**/*.d.ts"
],
"exclude": ["node_modules"]
]
}
Loading
Loading