mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
1f0dc8b754
This PR significantly expands the assistant documentation, breaking it out into sections, adding examples and further documenting features. This PR introduces a convention in docs for swapping keybindings for mac vs linux: `<kbd>cmd-enter|ctrl-enter</kbd>` In the above example, the first will be shown for mac, the second for linux or windows. TODO: - [ ] Fix table style (for `/assistant/configuration`) - [x] Add script to swap keybindings based on platform - It should take in this format: [`cmd-n` (mac)|`ctrl-n`(linux)] and return just the correct binding for the viewer's platform. - [ ] Add image/video assets (non-blocking) Release Notes: - Updated assistant documentation
51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
function detectOS() {
|
|
var userAgent = navigator.userAgent;
|
|
|
|
var platform = navigator.platform;
|
|
var macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K"];
|
|
var windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"];
|
|
var iosPlatforms = ["iPhone", "iPad", "iPod"];
|
|
|
|
if (macosPlatforms.indexOf(platform) !== -1) {
|
|
return "Mac";
|
|
} else if (iosPlatforms.indexOf(platform) !== -1) {
|
|
return "iOS";
|
|
} else if (windowsPlatforms.indexOf(platform) !== -1) {
|
|
return "Windows";
|
|
} else if (/Android/.test(userAgent)) {
|
|
return "Android";
|
|
} else if (/Linux/.test(platform)) {
|
|
return "Linux";
|
|
}
|
|
|
|
return "Unknown";
|
|
}
|
|
|
|
// Usage
|
|
var os = detectOS();
|
|
console.log("Operating System:", os);
|
|
|
|
(function updateKeybindings() {
|
|
const os = detectOS();
|
|
const isMac = os === "Mac" || os === "iOS";
|
|
|
|
function processKeybinding(element) {
|
|
const [macKeybinding, linuxKeybinding] = element.textContent.split("|");
|
|
element.textContent = isMac ? macKeybinding : linuxKeybinding;
|
|
element.classList.add("keybinding");
|
|
}
|
|
|
|
function walkDOM(node) {
|
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
if (node.tagName.toLowerCase() === "kbd") {
|
|
processKeybinding(node);
|
|
} else {
|
|
Array.from(node.children).forEach(walkDOM);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Start the process from the body
|
|
walkDOM(document.body);
|
|
})();
|