docstring_tokens
stringlengths 18
16.9k
| code_tokens
stringlengths 75
1.81M
| html_url
stringlengths 74
116
| file_name
stringlengths 3
311
|
---|---|---|---|
keep keep keep replace keep keep keep keep keep
|
<mask> {
<mask> "ar-SA": 98,
<mask> "bg-BG": 75,
<mask> "ca-ES": 94,
<mask> "de-DE": 100,
<mask> "el-GR": 92,
<mask> "en": 100,
<mask> "es-ES": 100,
<mask> "fa-IR": 98,
</s> New Crowdin updates (#2214)
* New translations en.json (Indonesian)
* New translations en.json (Polish)
* New translations en.json (Norwegian Bokmal)
* New translations en.json (Hindi)
* New translations en.json (Norwegian Nynorsk)
* New translations en.json (Tamil)
* New translations en.json (Galician)
* New translations en.json (Vietnamese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Chinese Simplified)
* New translations en.json (Ukrainian)
* New translations en.json (Turkish)
* New translations en.json (Swedish)
* New translations en.json (Albanian)
* New translations en.json (Russian)
* New translations en.json (Portuguese)
* New translations en.json (Dutch)
* New translations en.json (Persian)
* New translations en.json (Korean)
* New translations en.json (Japanese)
* New translations en.json (Italian)
* New translations en.json (Hungarian)
* New translations en.json (Hebrew)
* New translations en.json (Finnish)
* New translations en.json (Greek)
* New translations en.json (German)
* New translations en.json (Catalan)
* New translations en.json (Bulgarian)
* New translations en.json (Arabic)
* New translations en.json (Spanish)
* New translations en.json (French)
* New translations en.json (Romanian)
* New translations en.json (Nepali)
* Auto commit: Calculate translation coverage
* New translations en.json (French)
* New translations en.json (Portuguese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Norwegian Bokmal)
* Auto commit: Calculate translation coverage
* New translations en.json (Swedish)
* Auto commit: Calculate translation coverage
* New translations en.json (Dutch)
* Auto commit: Calculate translation coverage
* New translations en.json (Romanian)
* Auto commit: Calculate translation coverage
* New translations en.json (Catalan)
* Auto commit: Calculate translation coverage
* New translations en.json (Spanish)
* New translations en.json (Catalan)
* New translations en.json (Italian)
* Auto commit: Calculate translation coverage
* New translations en.json (Italian)
* New translations en.json (Portuguese)
* Auto commit: Calculate translation coverage
* New translations en.json (Finnish)
* Auto commit: Calculate translation coverage
* New translations en.json (Indonesian)
* Auto commit: Calculate translation coverage
* New translations en.json (German)
* Auto commit: Calculate translation coverage
Co-authored-by: Kostas Bariotis <[email protected]> </s> remove "ru-RU": 93,
</s> add "ru-RU": 92, </s> remove "nl-NL": 96,
"nn-NO": 100,
</s> add "nl-NL": 98,
"nn-NO": 99, </s> remove "tr-TR": 98,
"uk-UA": 100,
</s> add "tr-TR": 97,
"uk-UA": 99, </s> remove "pt-PT": 96,
</s> add "pt-PT": 100, </s> remove "ko-KR": 82,
</s> add "ko-KR": 81, </s> remove "preventBinding": ""
</s> add "preventBinding": "Prevenire l'associazione freccia"
|
https://github.com/excalidraw/excalidraw/commit/d012fda59d27f96d004a90efa55eb7dcbfb474a3
|
src/locales/percentages.json
|
keep replace keep keep replace keep keep
|
<mask> "he-IL": 85,
<mask> "hi-IN": 96,
<mask> "hu-HU": 54,
<mask> "id-ID": 100,
<mask> "it-IT": 95,
<mask> "ja-JP": 85,
<mask> "ko-KR": 82,
</s> New Crowdin updates (#2214)
* New translations en.json (Indonesian)
* New translations en.json (Polish)
* New translations en.json (Norwegian Bokmal)
* New translations en.json (Hindi)
* New translations en.json (Norwegian Nynorsk)
* New translations en.json (Tamil)
* New translations en.json (Galician)
* New translations en.json (Vietnamese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Chinese Simplified)
* New translations en.json (Ukrainian)
* New translations en.json (Turkish)
* New translations en.json (Swedish)
* New translations en.json (Albanian)
* New translations en.json (Russian)
* New translations en.json (Portuguese)
* New translations en.json (Dutch)
* New translations en.json (Persian)
* New translations en.json (Korean)
* New translations en.json (Japanese)
* New translations en.json (Italian)
* New translations en.json (Hungarian)
* New translations en.json (Hebrew)
* New translations en.json (Finnish)
* New translations en.json (Greek)
* New translations en.json (German)
* New translations en.json (Catalan)
* New translations en.json (Bulgarian)
* New translations en.json (Arabic)
* New translations en.json (Spanish)
* New translations en.json (French)
* New translations en.json (Romanian)
* New translations en.json (Nepali)
* Auto commit: Calculate translation coverage
* New translations en.json (French)
* New translations en.json (Portuguese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Norwegian Bokmal)
* Auto commit: Calculate translation coverage
* New translations en.json (Swedish)
* Auto commit: Calculate translation coverage
* New translations en.json (Dutch)
* Auto commit: Calculate translation coverage
* New translations en.json (Romanian)
* Auto commit: Calculate translation coverage
* New translations en.json (Catalan)
* Auto commit: Calculate translation coverage
* New translations en.json (Spanish)
* New translations en.json (Catalan)
* New translations en.json (Italian)
* Auto commit: Calculate translation coverage
* New translations en.json (Italian)
* New translations en.json (Portuguese)
* Auto commit: Calculate translation coverage
* New translations en.json (Finnish)
* Auto commit: Calculate translation coverage
* New translations en.json (Indonesian)
* Auto commit: Calculate translation coverage
* New translations en.json (German)
* Auto commit: Calculate translation coverage
Co-authored-by: Kostas Bariotis <[email protected]> </s> remove "ko-KR": 82,
</s> add "ko-KR": 81, </s> remove "nl-NL": 96,
"nn-NO": 100,
</s> add "nl-NL": 98,
"nn-NO": 99, </s> remove "pt-PT": 96,
</s> add "pt-PT": 100, </s> remove "ru-RU": 93,
</s> add "ru-RU": 92, </s> remove "ca-ES": 94,
</s> add "ca-ES": 100,
|
https://github.com/excalidraw/excalidraw/commit/d012fda59d27f96d004a90efa55eb7dcbfb474a3
|
src/locales/percentages.json
|
keep keep replace keep keep replace replace
|
<mask> "it-IT": 95,
<mask> "ja-JP": 85,
<mask> "ko-KR": 82,
<mask> "nb-NO": 100,
<mask> "ne-NP": 0,
<mask> "nl-NL": 96,
<mask> "nn-NO": 100,
</s> New Crowdin updates (#2214)
* New translations en.json (Indonesian)
* New translations en.json (Polish)
* New translations en.json (Norwegian Bokmal)
* New translations en.json (Hindi)
* New translations en.json (Norwegian Nynorsk)
* New translations en.json (Tamil)
* New translations en.json (Galician)
* New translations en.json (Vietnamese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Chinese Simplified)
* New translations en.json (Ukrainian)
* New translations en.json (Turkish)
* New translations en.json (Swedish)
* New translations en.json (Albanian)
* New translations en.json (Russian)
* New translations en.json (Portuguese)
* New translations en.json (Dutch)
* New translations en.json (Persian)
* New translations en.json (Korean)
* New translations en.json (Japanese)
* New translations en.json (Italian)
* New translations en.json (Hungarian)
* New translations en.json (Hebrew)
* New translations en.json (Finnish)
* New translations en.json (Greek)
* New translations en.json (German)
* New translations en.json (Catalan)
* New translations en.json (Bulgarian)
* New translations en.json (Arabic)
* New translations en.json (Spanish)
* New translations en.json (French)
* New translations en.json (Romanian)
* New translations en.json (Nepali)
* Auto commit: Calculate translation coverage
* New translations en.json (French)
* New translations en.json (Portuguese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Norwegian Bokmal)
* Auto commit: Calculate translation coverage
* New translations en.json (Swedish)
* Auto commit: Calculate translation coverage
* New translations en.json (Dutch)
* Auto commit: Calculate translation coverage
* New translations en.json (Romanian)
* Auto commit: Calculate translation coverage
* New translations en.json (Catalan)
* Auto commit: Calculate translation coverage
* New translations en.json (Spanish)
* New translations en.json (Catalan)
* New translations en.json (Italian)
* Auto commit: Calculate translation coverage
* New translations en.json (Italian)
* New translations en.json (Portuguese)
* Auto commit: Calculate translation coverage
* New translations en.json (Finnish)
* Auto commit: Calculate translation coverage
* New translations en.json (Indonesian)
* Auto commit: Calculate translation coverage
* New translations en.json (German)
* Auto commit: Calculate translation coverage
Co-authored-by: Kostas Bariotis <[email protected]> </s> remove "it-IT": 95,
</s> add "it-IT": 100, </s> remove "hi-IN": 96,
</s> add "hi-IN": 95, </s> remove "pt-PT": 96,
</s> add "pt-PT": 100, </s> remove "ru-RU": 93,
</s> add "ru-RU": 92, </s> remove "tr-TR": 98,
"uk-UA": 100,
</s> add "tr-TR": 97,
"uk-UA": 99,
|
https://github.com/excalidraw/excalidraw/commit/d012fda59d27f96d004a90efa55eb7dcbfb474a3
|
src/locales/percentages.json
|
keep keep replace keep replace keep keep keep keep
|
<mask> "nn-NO": 100,
<mask> "pl-PL": 98,
<mask> "pt-PT": 96,
<mask> "ro-RO": 100,
<mask> "ru-RU": 93,
<mask> "sq-AL": 38,
<mask> "sv-SE": 100,
<mask> "ta-IN": 6,
<mask> "tr-TR": 98,
</s> New Crowdin updates (#2214)
* New translations en.json (Indonesian)
* New translations en.json (Polish)
* New translations en.json (Norwegian Bokmal)
* New translations en.json (Hindi)
* New translations en.json (Norwegian Nynorsk)
* New translations en.json (Tamil)
* New translations en.json (Galician)
* New translations en.json (Vietnamese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Chinese Simplified)
* New translations en.json (Ukrainian)
* New translations en.json (Turkish)
* New translations en.json (Swedish)
* New translations en.json (Albanian)
* New translations en.json (Russian)
* New translations en.json (Portuguese)
* New translations en.json (Dutch)
* New translations en.json (Persian)
* New translations en.json (Korean)
* New translations en.json (Japanese)
* New translations en.json (Italian)
* New translations en.json (Hungarian)
* New translations en.json (Hebrew)
* New translations en.json (Finnish)
* New translations en.json (Greek)
* New translations en.json (German)
* New translations en.json (Catalan)
* New translations en.json (Bulgarian)
* New translations en.json (Arabic)
* New translations en.json (Spanish)
* New translations en.json (French)
* New translations en.json (Romanian)
* New translations en.json (Nepali)
* Auto commit: Calculate translation coverage
* New translations en.json (French)
* New translations en.json (Portuguese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Norwegian Bokmal)
* Auto commit: Calculate translation coverage
* New translations en.json (Swedish)
* Auto commit: Calculate translation coverage
* New translations en.json (Dutch)
* Auto commit: Calculate translation coverage
* New translations en.json (Romanian)
* Auto commit: Calculate translation coverage
* New translations en.json (Catalan)
* Auto commit: Calculate translation coverage
* New translations en.json (Spanish)
* New translations en.json (Catalan)
* New translations en.json (Italian)
* Auto commit: Calculate translation coverage
* New translations en.json (Italian)
* New translations en.json (Portuguese)
* Auto commit: Calculate translation coverage
* New translations en.json (Finnish)
* Auto commit: Calculate translation coverage
* New translations en.json (Indonesian)
* Auto commit: Calculate translation coverage
* New translations en.json (German)
* Auto commit: Calculate translation coverage
Co-authored-by: Kostas Bariotis <[email protected]> </s> remove "tr-TR": 98,
"uk-UA": 100,
</s> add "tr-TR": 97,
"uk-UA": 99, </s> remove "nl-NL": 96,
"nn-NO": 100,
</s> add "nl-NL": 98,
"nn-NO": 99, </s> remove "ko-KR": 82,
</s> add "ko-KR": 81, </s> remove "ca-ES": 94,
</s> add "ca-ES": 100, </s> remove "it-IT": 95,
</s> add "it-IT": 100,
|
https://github.com/excalidraw/excalidraw/commit/d012fda59d27f96d004a90efa55eb7dcbfb474a3
|
src/locales/percentages.json
|
keep keep keep keep replace replace keep keep keep keep
|
<mask> "ru-RU": 93,
<mask> "sq-AL": 38,
<mask> "sv-SE": 100,
<mask> "ta-IN": 6,
<mask> "tr-TR": 98,
<mask> "uk-UA": 100,
<mask> "vi-VN": 0,
<mask> "zh-CN": 98,
<mask> "zh-TW": 98
<mask> }
</s> New Crowdin updates (#2214)
* New translations en.json (Indonesian)
* New translations en.json (Polish)
* New translations en.json (Norwegian Bokmal)
* New translations en.json (Hindi)
* New translations en.json (Norwegian Nynorsk)
* New translations en.json (Tamil)
* New translations en.json (Galician)
* New translations en.json (Vietnamese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Chinese Simplified)
* New translations en.json (Ukrainian)
* New translations en.json (Turkish)
* New translations en.json (Swedish)
* New translations en.json (Albanian)
* New translations en.json (Russian)
* New translations en.json (Portuguese)
* New translations en.json (Dutch)
* New translations en.json (Persian)
* New translations en.json (Korean)
* New translations en.json (Japanese)
* New translations en.json (Italian)
* New translations en.json (Hungarian)
* New translations en.json (Hebrew)
* New translations en.json (Finnish)
* New translations en.json (Greek)
* New translations en.json (German)
* New translations en.json (Catalan)
* New translations en.json (Bulgarian)
* New translations en.json (Arabic)
* New translations en.json (Spanish)
* New translations en.json (French)
* New translations en.json (Romanian)
* New translations en.json (Nepali)
* Auto commit: Calculate translation coverage
* New translations en.json (French)
* New translations en.json (Portuguese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Norwegian Bokmal)
* Auto commit: Calculate translation coverage
* New translations en.json (Swedish)
* Auto commit: Calculate translation coverage
* New translations en.json (Dutch)
* Auto commit: Calculate translation coverage
* New translations en.json (Romanian)
* Auto commit: Calculate translation coverage
* New translations en.json (Catalan)
* Auto commit: Calculate translation coverage
* New translations en.json (Spanish)
* New translations en.json (Catalan)
* New translations en.json (Italian)
* Auto commit: Calculate translation coverage
* New translations en.json (Italian)
* New translations en.json (Portuguese)
* Auto commit: Calculate translation coverage
* New translations en.json (Finnish)
* Auto commit: Calculate translation coverage
* New translations en.json (Indonesian)
* Auto commit: Calculate translation coverage
* New translations en.json (German)
* Auto commit: Calculate translation coverage
Co-authored-by: Kostas Bariotis <[email protected]> </s> remove "ru-RU": 93,
</s> add "ru-RU": 92, </s> remove "pt-PT": 96,
</s> add "pt-PT": 100, </s> remove "nl-NL": 96,
"nn-NO": 100,
</s> add "nl-NL": 98,
"nn-NO": 99, </s> remove "ko-KR": 82,
</s> add "ko-KR": 81, </s> remove "ca-ES": 94,
</s> add "ca-ES": 100, </s> remove "it-IT": 95,
</s> add "it-IT": 100,
|
https://github.com/excalidraw/excalidraw/commit/d012fda59d27f96d004a90efa55eb7dcbfb474a3
|
src/locales/percentages.json
|
keep keep add keep keep keep keep keep
|
<mask> "exportToSvg": "",
<mask> "copyToClipboard": "",
<mask> "copyPngToClipboard": "",
<mask> "save": "",
<mask> "saveAs": "",
<mask> "load": "",
<mask> "getShareableLink": "",
<mask> "close": "",
</s> New Crowdin updates (#2214)
* New translations en.json (Indonesian)
* New translations en.json (Polish)
* New translations en.json (Norwegian Bokmal)
* New translations en.json (Hindi)
* New translations en.json (Norwegian Nynorsk)
* New translations en.json (Tamil)
* New translations en.json (Galician)
* New translations en.json (Vietnamese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Chinese Simplified)
* New translations en.json (Ukrainian)
* New translations en.json (Turkish)
* New translations en.json (Swedish)
* New translations en.json (Albanian)
* New translations en.json (Russian)
* New translations en.json (Portuguese)
* New translations en.json (Dutch)
* New translations en.json (Persian)
* New translations en.json (Korean)
* New translations en.json (Japanese)
* New translations en.json (Italian)
* New translations en.json (Hungarian)
* New translations en.json (Hebrew)
* New translations en.json (Finnish)
* New translations en.json (Greek)
* New translations en.json (German)
* New translations en.json (Catalan)
* New translations en.json (Bulgarian)
* New translations en.json (Arabic)
* New translations en.json (Spanish)
* New translations en.json (French)
* New translations en.json (Romanian)
* New translations en.json (Nepali)
* Auto commit: Calculate translation coverage
* New translations en.json (French)
* New translations en.json (Portuguese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Norwegian Bokmal)
* Auto commit: Calculate translation coverage
* New translations en.json (Swedish)
* Auto commit: Calculate translation coverage
* New translations en.json (Dutch)
* Auto commit: Calculate translation coverage
* New translations en.json (Romanian)
* Auto commit: Calculate translation coverage
* New translations en.json (Catalan)
* Auto commit: Calculate translation coverage
* New translations en.json (Spanish)
* New translations en.json (Catalan)
* New translations en.json (Italian)
* Auto commit: Calculate translation coverage
* New translations en.json (Italian)
* New translations en.json (Portuguese)
* Auto commit: Calculate translation coverage
* New translations en.json (Finnish)
* Auto commit: Calculate translation coverage
* New translations en.json (Indonesian)
* Auto commit: Calculate translation coverage
* New translations en.json (German)
* Auto commit: Calculate translation coverage
Co-authored-by: Kostas Bariotis <[email protected]>
|
https://github.com/excalidraw/excalidraw/commit/d012fda59d27f96d004a90efa55eb7dcbfb474a3
|
src/locales/sq-AL.json
|
keep add keep keep keep keep keep
|
<mask> "copyToClipboard": "",
<mask> "copyPngToClipboard": "",
<mask> "save": "",
<mask> "saveAs": "",
<mask> "load": "",
<mask> "getShareableLink": "",
<mask> "close": "",
</s> New Crowdin updates (#2214)
* New translations en.json (Indonesian)
* New translations en.json (Polish)
* New translations en.json (Norwegian Bokmal)
* New translations en.json (Hindi)
* New translations en.json (Norwegian Nynorsk)
* New translations en.json (Tamil)
* New translations en.json (Galician)
* New translations en.json (Vietnamese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Chinese Simplified)
* New translations en.json (Ukrainian)
* New translations en.json (Turkish)
* New translations en.json (Swedish)
* New translations en.json (Albanian)
* New translations en.json (Russian)
* New translations en.json (Portuguese)
* New translations en.json (Dutch)
* New translations en.json (Persian)
* New translations en.json (Korean)
* New translations en.json (Japanese)
* New translations en.json (Italian)
* New translations en.json (Hungarian)
* New translations en.json (Hebrew)
* New translations en.json (Finnish)
* New translations en.json (Greek)
* New translations en.json (German)
* New translations en.json (Catalan)
* New translations en.json (Bulgarian)
* New translations en.json (Arabic)
* New translations en.json (Spanish)
* New translations en.json (French)
* New translations en.json (Romanian)
* New translations en.json (Nepali)
* Auto commit: Calculate translation coverage
* New translations en.json (French)
* New translations en.json (Portuguese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Norwegian Bokmal)
* Auto commit: Calculate translation coverage
* New translations en.json (Swedish)
* Auto commit: Calculate translation coverage
* New translations en.json (Dutch)
* Auto commit: Calculate translation coverage
* New translations en.json (Romanian)
* Auto commit: Calculate translation coverage
* New translations en.json (Catalan)
* Auto commit: Calculate translation coverage
* New translations en.json (Spanish)
* New translations en.json (Catalan)
* New translations en.json (Italian)
* Auto commit: Calculate translation coverage
* New translations en.json (Italian)
* New translations en.json (Portuguese)
* Auto commit: Calculate translation coverage
* New translations en.json (Finnish)
* Auto commit: Calculate translation coverage
* New translations en.json (Indonesian)
* Auto commit: Calculate translation coverage
* New translations en.json (German)
* Auto commit: Calculate translation coverage
Co-authored-by: Kostas Bariotis <[email protected]> </s> add "scale": "", </s> add "scale": "", </s> add "scale": "", </s> add "scale": "", </s> remove "sharp": "",
</s> add "sharp": "Hoekig", </s> add "scale": "Scala",
|
https://github.com/excalidraw/excalidraw/commit/d012fda59d27f96d004a90efa55eb7dcbfb474a3
|
src/locales/ta-IN.json
|
keep keep add keep keep keep keep keep keep
|
<mask> "exportToSvg": "",
<mask> "copyToClipboard": "",
<mask> "copyPngToClipboard": "",
<mask> "save": "",
<mask> "saveAs": "",
<mask> "load": "",
<mask> "getShareableLink": "",
<mask> "close": "",
<mask> "selectLanguage": "",
</s> New Crowdin updates (#2214)
* New translations en.json (Indonesian)
* New translations en.json (Polish)
* New translations en.json (Norwegian Bokmal)
* New translations en.json (Hindi)
* New translations en.json (Norwegian Nynorsk)
* New translations en.json (Tamil)
* New translations en.json (Galician)
* New translations en.json (Vietnamese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Chinese Simplified)
* New translations en.json (Ukrainian)
* New translations en.json (Turkish)
* New translations en.json (Swedish)
* New translations en.json (Albanian)
* New translations en.json (Russian)
* New translations en.json (Portuguese)
* New translations en.json (Dutch)
* New translations en.json (Persian)
* New translations en.json (Korean)
* New translations en.json (Japanese)
* New translations en.json (Italian)
* New translations en.json (Hungarian)
* New translations en.json (Hebrew)
* New translations en.json (Finnish)
* New translations en.json (Greek)
* New translations en.json (German)
* New translations en.json (Catalan)
* New translations en.json (Bulgarian)
* New translations en.json (Arabic)
* New translations en.json (Spanish)
* New translations en.json (French)
* New translations en.json (Romanian)
* New translations en.json (Nepali)
* Auto commit: Calculate translation coverage
* New translations en.json (French)
* New translations en.json (Portuguese)
* New translations en.json (Chinese Traditional)
* New translations en.json (Norwegian Bokmal)
* Auto commit: Calculate translation coverage
* New translations en.json (Swedish)
* Auto commit: Calculate translation coverage
* New translations en.json (Dutch)
* Auto commit: Calculate translation coverage
* New translations en.json (Romanian)
* Auto commit: Calculate translation coverage
* New translations en.json (Catalan)
* Auto commit: Calculate translation coverage
* New translations en.json (Spanish)
* New translations en.json (Catalan)
* New translations en.json (Italian)
* Auto commit: Calculate translation coverage
* New translations en.json (Italian)
* New translations en.json (Portuguese)
* Auto commit: Calculate translation coverage
* New translations en.json (Finnish)
* Auto commit: Calculate translation coverage
* New translations en.json (Indonesian)
* Auto commit: Calculate translation coverage
* New translations en.json (German)
* Auto commit: Calculate translation coverage
Co-authored-by: Kostas Bariotis <[email protected]> </s> add "scale": "", </s> add "scale": "", </s> add "scale": "", </s> add "scale": "", </s> remove "sharp": "",
</s> add "sharp": "Hoekig", </s> add "scale": "Schaal",
|
https://github.com/excalidraw/excalidraw/commit/d012fda59d27f96d004a90efa55eb7dcbfb474a3
|
src/locales/vi-VN.json
|
keep add keep keep keep keep
|
<mask> import { ColorPicker } from "./components/ColorPicker";
<mask> import { SHAPES, findShapeByKey, shapesShortcutKeys } from "./shapes";
<mask>
<mask> import "./styles.scss";
<mask>
<mask> const { elements } = createScene();
</s> Extract history (#213)
* Extract History into its own module
* Encapsulate undo and redo actions within history
* Encapsulate clearing redo stack within History
* Add private access modifiers to scene history class member variables
* Remove duplicate files </s> add const { history } = createHistory(); </s> remove let skipHistory = false;
const stateHistory: string[] = [];
const redoStack: string[] = [];
function generateHistoryCurrentEntry() {
return JSON.stringify(
elements.map(element => ({ ...element, isSelected: false }))
);
}
function pushHistoryEntry(newEntry: string) {
if (
stateHistory.length > 0 &&
stateHistory[stateHistory.length - 1] === newEntry
) {
// If the last entry is the same as this one, ignore it
return;
}
stateHistory.push(newEntry);
}
function restoreHistoryEntry(entry: string) {
const newElements = JSON.parse(entry);
elements.splice(0, elements.length);
newElements.forEach((newElement: ExcalidrawElement) => {
generateDraw(newElement);
elements.push(newElement);
});
// When restoring, we shouldn't add an history entry otherwise we'll be stuck with it and can't go back
skipHistory = true;
}
</s> add </s> remove const currentEntry = generateHistoryCurrentEntry();
</s> add </s> remove const entryToRestore = redoStack.pop();
if (entryToRestore !== undefined) {
restoreHistoryEntry(entryToRestore);
stateHistory.push(currentEntry);
}
</s> add history.redoOnce(elements); </s> remove skipHistory = false;
</s> add history.resumeRecording(); </s> remove skipHistory = true;
</s> add history.skipRecording();
|
https://github.com/excalidraw/excalidraw/commit/d0365933a93d7ecb136510f0060a8ea1321cda34
|
src/index.tsx
|
keep keep keep add keep keep keep keep
|
<mask>
<mask> import "./styles.scss";
<mask>
<mask> const { elements } = createScene();
<mask>
<mask> const DEFAULT_PROJECT_NAME = `excalidraw-${getDateTime()}`;
<mask>
<mask> const CANVAS_WINDOW_OFFSET_LEFT = 250;
</s> Extract history (#213)
* Extract History into its own module
* Encapsulate undo and redo actions within history
* Encapsulate clearing redo stack within History
* Add private access modifiers to scene history class member variables
* Remove duplicate files </s> add import { createHistory } from "./history"; </s> remove let skipHistory = false;
const stateHistory: string[] = [];
const redoStack: string[] = [];
function generateHistoryCurrentEntry() {
return JSON.stringify(
elements.map(element => ({ ...element, isSelected: false }))
);
}
function pushHistoryEntry(newEntry: string) {
if (
stateHistory.length > 0 &&
stateHistory[stateHistory.length - 1] === newEntry
) {
// If the last entry is the same as this one, ignore it
return;
}
stateHistory.push(newEntry);
}
function restoreHistoryEntry(entry: string) {
const newElements = JSON.parse(entry);
elements.splice(0, elements.length);
newElements.forEach((newElement: ExcalidrawElement) => {
generateDraw(newElement);
elements.push(newElement);
});
// When restoring, we shouldn't add an history entry otherwise we'll be stuck with it and can't go back
skipHistory = true;
}
</s> add </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove skipHistory = false;
</s> add history.resumeRecording(); </s> remove const currentEntry = generateHistoryCurrentEntry();
</s> add </s> remove const entryToRestore = redoStack.pop();
if (entryToRestore !== undefined) {
restoreHistoryEntry(entryToRestore);
stateHistory.push(currentEntry);
}
</s> add history.redoOnce(elements);
|
https://github.com/excalidraw/excalidraw/commit/d0365933a93d7ecb136510f0060a8ea1321cda34
|
src/index.tsx
|
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
|
<mask> const { elements } = createScene();
<mask>
<mask> const DEFAULT_PROJECT_NAME = `excalidraw-${getDateTime()}`;
<mask>
<mask> let skipHistory = false;
<mask> const stateHistory: string[] = [];
<mask> const redoStack: string[] = [];
<mask>
<mask> function generateHistoryCurrentEntry() {
<mask> return JSON.stringify(
<mask> elements.map(element => ({ ...element, isSelected: false }))
<mask> );
<mask> }
<mask> function pushHistoryEntry(newEntry: string) {
<mask> if (
<mask> stateHistory.length > 0 &&
<mask> stateHistory[stateHistory.length - 1] === newEntry
<mask> ) {
<mask> // If the last entry is the same as this one, ignore it
<mask> return;
<mask> }
<mask> stateHistory.push(newEntry);
<mask> }
<mask> function restoreHistoryEntry(entry: string) {
<mask> const newElements = JSON.parse(entry);
<mask> elements.splice(0, elements.length);
<mask> newElements.forEach((newElement: ExcalidrawElement) => {
<mask> generateDraw(newElement);
<mask> elements.push(newElement);
<mask> });
<mask> // When restoring, we shouldn't add an history entry otherwise we'll be stuck with it and can't go back
<mask> skipHistory = true;
<mask> }
<mask>
<mask> const CANVAS_WINDOW_OFFSET_LEFT = 250;
<mask> const CANVAS_WINDOW_OFFSET_TOP = 0;
<mask>
<mask> const KEYS = {
<mask> ARROW_LEFT: "ArrowLeft",
</s> Extract history (#213)
* Extract History into its own module
* Encapsulate undo and redo actions within history
* Encapsulate clearing redo stack within History
* Add private access modifiers to scene history class member variables
* Remove duplicate files </s> add const { history } = createHistory(); </s> remove const entryToRestore = redoStack.pop();
if (entryToRestore !== undefined) {
restoreHistoryEntry(entryToRestore);
stateHistory.push(currentEntry);
}
</s> add history.redoOnce(elements); </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove const currentEntry = generateHistoryCurrentEntry();
</s> add </s> remove skipHistory = false;
</s> add history.resumeRecording(); </s> add import { createHistory } from "./history";
|
https://github.com/excalidraw/excalidraw/commit/d0365933a93d7ecb136510f0060a8ea1321cda34
|
src/index.tsx
|
keep replace keep keep replace replace replace replace replace keep keep keep keep
|
<mask> } else if (event.metaKey && event.code === "KeyZ") {
<mask> const currentEntry = generateHistoryCurrentEntry();
<mask> if (event.shiftKey) {
<mask> // Redo action
<mask> const entryToRestore = redoStack.pop();
<mask> if (entryToRestore !== undefined) {
<mask> restoreHistoryEntry(entryToRestore);
<mask> stateHistory.push(currentEntry);
<mask> }
<mask> } else {
<mask> // undo action
<mask> let lastEntry = stateHistory.pop();
<mask> // If nothing was changed since last, take the previous one
</s> Extract history (#213)
* Extract History into its own module
* Encapsulate undo and redo actions within history
* Encapsulate clearing redo stack within History
* Add private access modifiers to scene history class member variables
* Remove duplicate files </s> remove let lastEntry = stateHistory.pop();
// If nothing was changed since last, take the previous one
if (currentEntry === lastEntry) {
lastEntry = stateHistory.pop();
}
if (lastEntry !== undefined) {
restoreHistoryEntry(lastEntry);
redoStack.push(currentEntry);
}
</s> add history.undoOnce(elements); </s> remove let skipHistory = false;
const stateHistory: string[] = [];
const redoStack: string[] = [];
function generateHistoryCurrentEntry() {
return JSON.stringify(
elements.map(element => ({ ...element, isSelected: false }))
);
}
function pushHistoryEntry(newEntry: string) {
if (
stateHistory.length > 0 &&
stateHistory[stateHistory.length - 1] === newEntry
) {
// If the last entry is the same as this one, ignore it
return;
}
stateHistory.push(newEntry);
}
function restoreHistoryEntry(entry: string) {
const newElements = JSON.parse(entry);
elements.splice(0, elements.length);
newElements.forEach((newElement: ExcalidrawElement) => {
generateDraw(newElement);
elements.push(newElement);
});
// When restoring, we shouldn't add an history entry otherwise we'll be stuck with it and can't go back
skipHistory = true;
}
</s> add </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove skipHistory = false;
</s> add history.resumeRecording(); </s> add const { history } = createHistory();
|
https://github.com/excalidraw/excalidraw/commit/d0365933a93d7ecb136510f0060a8ea1321cda34
|
src/index.tsx
|
keep keep keep keep replace replace replace replace replace replace replace replace replace keep keep keep keep keep
|
<mask> stateHistory.push(currentEntry);
<mask> }
<mask> } else {
<mask> // undo action
<mask> let lastEntry = stateHistory.pop();
<mask> // If nothing was changed since last, take the previous one
<mask> if (currentEntry === lastEntry) {
<mask> lastEntry = stateHistory.pop();
<mask> }
<mask> if (lastEntry !== undefined) {
<mask> restoreHistoryEntry(lastEntry);
<mask> redoStack.push(currentEntry);
<mask> }
<mask> }
<mask> this.forceUpdate();
<mask> event.preventDefault();
<mask> }
<mask> };
</s> Extract history (#213)
* Extract History into its own module
* Encapsulate undo and redo actions within history
* Encapsulate clearing redo stack within History
* Add private access modifiers to scene history class member variables
* Remove duplicate files </s> remove const entryToRestore = redoStack.pop();
if (entryToRestore !== undefined) {
restoreHistoryEntry(entryToRestore);
stateHistory.push(currentEntry);
}
</s> add history.redoOnce(elements); </s> remove const currentEntry = generateHistoryCurrentEntry();
</s> add </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove let skipHistory = false;
const stateHistory: string[] = [];
const redoStack: string[] = [];
function generateHistoryCurrentEntry() {
return JSON.stringify(
elements.map(element => ({ ...element, isSelected: false }))
);
}
function pushHistoryEntry(newEntry: string) {
if (
stateHistory.length > 0 &&
stateHistory[stateHistory.length - 1] === newEntry
) {
// If the last entry is the same as this one, ignore it
return;
}
stateHistory.push(newEntry);
}
function restoreHistoryEntry(entry: string) {
const newElements = JSON.parse(entry);
elements.splice(0, elements.length);
newElements.forEach((newElement: ExcalidrawElement) => {
generateDraw(newElement);
elements.push(newElement);
});
// When restoring, we shouldn't add an history entry otherwise we'll be stuck with it and can't go back
skipHistory = true;
}
</s> add </s> remove if (!skipHistory) {
pushHistoryEntry(generateHistoryCurrentEntry());
redoStack.splice(0, redoStack.length);
</s> add if (history.isRecording()) {
history.pushEntry(history.generateCurrentEntry(elements));
history.clearRedoStack(); </s> remove skipHistory = false;
</s> add history.resumeRecording();
|
https://github.com/excalidraw/excalidraw/commit/d0365933a93d7ecb136510f0060a8ea1321cda34
|
src/index.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> });
<mask> lastX = x;
<mask> lastY = y;
<mask> // We don't want to save history when resizing an element
<mask> skipHistory = true;
<mask> this.forceUpdate();
<mask> return;
<mask> }
<mask> }
<mask>
</s> Extract history (#213)
* Extract History into its own module
* Encapsulate undo and redo actions within history
* Encapsulate clearing redo stack within History
* Add private access modifiers to scene history class member variables
* Remove duplicate files </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove let skipHistory = false;
const stateHistory: string[] = [];
const redoStack: string[] = [];
function generateHistoryCurrentEntry() {
return JSON.stringify(
elements.map(element => ({ ...element, isSelected: false }))
);
}
function pushHistoryEntry(newEntry: string) {
if (
stateHistory.length > 0 &&
stateHistory[stateHistory.length - 1] === newEntry
) {
// If the last entry is the same as this one, ignore it
return;
}
stateHistory.push(newEntry);
}
function restoreHistoryEntry(entry: string) {
const newElements = JSON.parse(entry);
elements.splice(0, elements.length);
newElements.forEach((newElement: ExcalidrawElement) => {
generateDraw(newElement);
elements.push(newElement);
});
// When restoring, we shouldn't add an history entry otherwise we'll be stuck with it and can't go back
skipHistory = true;
}
</s> add </s> remove skipHistory = false;
</s> add history.resumeRecording(); </s> remove let lastEntry = stateHistory.pop();
// If nothing was changed since last, take the previous one
if (currentEntry === lastEntry) {
lastEntry = stateHistory.pop();
}
if (lastEntry !== undefined) {
restoreHistoryEntry(lastEntry);
redoStack.push(currentEntry);
}
</s> add history.undoOnce(elements);
|
https://github.com/excalidraw/excalidraw/commit/d0365933a93d7ecb136510f0060a8ea1321cda34
|
src/index.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> });
<mask> lastX = x;
<mask> lastY = y;
<mask> // We don't want to save history when dragging an element to initially size it
<mask> skipHistory = true;
<mask> this.forceUpdate();
<mask> return;
<mask> }
<mask> }
<mask>
</s> Extract history (#213)
* Extract History into its own module
* Encapsulate undo and redo actions within history
* Encapsulate clearing redo stack within History
* Add private access modifiers to scene history class member variables
* Remove duplicate files </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove let skipHistory = false;
const stateHistory: string[] = [];
const redoStack: string[] = [];
function generateHistoryCurrentEntry() {
return JSON.stringify(
elements.map(element => ({ ...element, isSelected: false }))
);
}
function pushHistoryEntry(newEntry: string) {
if (
stateHistory.length > 0 &&
stateHistory[stateHistory.length - 1] === newEntry
) {
// If the last entry is the same as this one, ignore it
return;
}
stateHistory.push(newEntry);
}
function restoreHistoryEntry(entry: string) {
const newElements = JSON.parse(entry);
elements.splice(0, elements.length);
newElements.forEach((newElement: ExcalidrawElement) => {
generateDraw(newElement);
elements.push(newElement);
});
// When restoring, we shouldn't add an history entry otherwise we'll be stuck with it and can't go back
skipHistory = true;
}
</s> add </s> remove skipHistory = false;
</s> add history.resumeRecording(); </s> remove let lastEntry = stateHistory.pop();
// If nothing was changed since last, take the previous one
if (currentEntry === lastEntry) {
lastEntry = stateHistory.pop();
}
if (lastEntry !== undefined) {
restoreHistoryEntry(lastEntry);
redoStack.push(currentEntry);
}
</s> add history.undoOnce(elements);
|
https://github.com/excalidraw/excalidraw/commit/d0365933a93d7ecb136510f0060a8ea1321cda34
|
src/index.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> if (this.state.elementType === "selection") {
<mask> setSelection(elements, draggingElement);
<mask> }
<mask> // We don't want to save history when moving an element
<mask> skipHistory = true;
<mask> this.forceUpdate();
<mask> };
<mask>
<mask> const onMouseUp = (e: MouseEvent) => {
<mask> const { draggingElement, elementType } = this.state;
</s> Extract history (#213)
* Extract History into its own module
* Encapsulate undo and redo actions within history
* Encapsulate clearing redo stack within History
* Add private access modifiers to scene history class member variables
* Remove duplicate files </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove let skipHistory = false;
const stateHistory: string[] = [];
const redoStack: string[] = [];
function generateHistoryCurrentEntry() {
return JSON.stringify(
elements.map(element => ({ ...element, isSelected: false }))
);
}
function pushHistoryEntry(newEntry: string) {
if (
stateHistory.length > 0 &&
stateHistory[stateHistory.length - 1] === newEntry
) {
// If the last entry is the same as this one, ignore it
return;
}
stateHistory.push(newEntry);
}
function restoreHistoryEntry(entry: string) {
const newElements = JSON.parse(entry);
elements.splice(0, elements.length);
newElements.forEach((newElement: ExcalidrawElement) => {
generateDraw(newElement);
elements.push(newElement);
});
// When restoring, we shouldn't add an history entry otherwise we'll be stuck with it and can't go back
skipHistory = true;
}
</s> add </s> remove let lastEntry = stateHistory.pop();
// If nothing was changed since last, take the previous one
if (currentEntry === lastEntry) {
lastEntry = stateHistory.pop();
}
if (lastEntry !== undefined) {
restoreHistoryEntry(lastEntry);
redoStack.push(currentEntry);
}
</s> add history.undoOnce(elements); </s> remove const entryToRestore = redoStack.pop();
if (entryToRestore !== undefined) {
restoreHistoryEntry(entryToRestore);
stateHistory.push(currentEntry);
}
</s> add history.redoOnce(elements);
|
https://github.com/excalidraw/excalidraw/commit/d0365933a93d7ecb136510f0060a8ea1321cda34
|
src/index.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> window.addEventListener("mousemove", onMouseMove);
<mask> window.addEventListener("mouseup", onMouseUp);
<mask>
<mask> // We don't want to save history on mouseDown, only on mouseUp when it's fully configured
<mask> skipHistory = true;
<mask> this.forceUpdate();
<mask> }}
<mask> onDoubleClick={e => {
<mask> const x =
<mask> e.clientX - CANVAS_WINDOW_OFFSET_LEFT - this.state.scrollX;
</s> Extract history (#213)
* Extract History into its own module
* Encapsulate undo and redo actions within history
* Encapsulate clearing redo stack within History
* Add private access modifiers to scene history class member variables
* Remove duplicate files </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove let skipHistory = false;
const stateHistory: string[] = [];
const redoStack: string[] = [];
function generateHistoryCurrentEntry() {
return JSON.stringify(
elements.map(element => ({ ...element, isSelected: false }))
);
}
function pushHistoryEntry(newEntry: string) {
if (
stateHistory.length > 0 &&
stateHistory[stateHistory.length - 1] === newEntry
) {
// If the last entry is the same as this one, ignore it
return;
}
stateHistory.push(newEntry);
}
function restoreHistoryEntry(entry: string) {
const newElements = JSON.parse(entry);
elements.splice(0, elements.length);
newElements.forEach((newElement: ExcalidrawElement) => {
generateDraw(newElement);
elements.push(newElement);
});
// When restoring, we shouldn't add an history entry otherwise we'll be stuck with it and can't go back
skipHistory = true;
}
</s> add </s> add const { history } = createHistory(); </s> remove const entryToRestore = redoStack.pop();
if (entryToRestore !== undefined) {
restoreHistoryEntry(entryToRestore);
stateHistory.push(currentEntry);
}
</s> add history.redoOnce(elements);
|
https://github.com/excalidraw/excalidraw/commit/d0365933a93d7ecb136510f0060a8ea1321cda34
|
src/index.tsx
|
keep keep keep replace replace replace keep replace
|
<mask> viewBackgroundColor: this.state.viewBackgroundColor
<mask> });
<mask> saveToLocalStorage(elements, this.state);
<mask> if (!skipHistory) {
<mask> pushHistoryEntry(generateHistoryCurrentEntry());
<mask> redoStack.splice(0, redoStack.length);
<mask> }
<mask> skipHistory = false;
</s> Extract history (#213)
* Extract History into its own module
* Encapsulate undo and redo actions within history
* Encapsulate clearing redo stack within History
* Add private access modifiers to scene history class member variables
* Remove duplicate files </s> remove let skipHistory = false;
const stateHistory: string[] = [];
const redoStack: string[] = [];
function generateHistoryCurrentEntry() {
return JSON.stringify(
elements.map(element => ({ ...element, isSelected: false }))
);
}
function pushHistoryEntry(newEntry: string) {
if (
stateHistory.length > 0 &&
stateHistory[stateHistory.length - 1] === newEntry
) {
// If the last entry is the same as this one, ignore it
return;
}
stateHistory.push(newEntry);
}
function restoreHistoryEntry(entry: string) {
const newElements = JSON.parse(entry);
elements.splice(0, elements.length);
newElements.forEach((newElement: ExcalidrawElement) => {
generateDraw(newElement);
elements.push(newElement);
});
// When restoring, we shouldn't add an history entry otherwise we'll be stuck with it and can't go back
skipHistory = true;
}
</s> add </s> remove const currentEntry = generateHistoryCurrentEntry();
</s> add </s> remove skipHistory = true;
</s> add history.skipRecording(); </s> remove const entryToRestore = redoStack.pop();
if (entryToRestore !== undefined) {
restoreHistoryEntry(entryToRestore);
stateHistory.push(currentEntry);
}
</s> add history.redoOnce(elements); </s> remove let lastEntry = stateHistory.pop();
// If nothing was changed since last, take the previous one
if (currentEntry === lastEntry) {
lastEntry = stateHistory.pop();
}
if (lastEntry !== undefined) {
restoreHistoryEntry(lastEntry);
redoStack.push(currentEntry);
}
</s> add history.undoOnce(elements);
|
https://github.com/excalidraw/excalidraw/commit/d0365933a93d7ecb136510f0060a8ea1321cda34
|
src/index.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> import { t } from "../i18n";
<mask> import { getShortcutKey } from "../utils";
<mask> import { LinearElementEditor } from "../element/linearElementEditor";
<mask> import { mutateElement } from "../element/mutateElement";
<mask> import { selectGroupsForSelectedElements } from "../groups";
<mask> import { AppState } from "../types";
<mask> import { fixBindingsAfterDuplication } from "../element/binding";
<mask> import { ActionResult } from "./types";
<mask>
<mask> export const actionDuplicateSelection = register({
</s> fix zindex to account for group boundaries (#2065) </s> add actionDuplicateSelection, </s> add import { AppState } from "../types"; </s> remove const swap = <T>(elements: T[], indexA: number, indexB: number) => {
const element = elements[indexA];
elements[indexA] = elements[indexB];
elements[indexB] = element;
};
</s> add import { AppState } from "./types";
import { ExcalidrawElement } from "./element/types";
import { getElementsInGroup } from "./groups";
import { findLastIndex, findIndex } from "./utils"; </s> remove // We go from the next marker to the left (i - 1) to the current one (index)
for (let pos = indicesToMove[i - 1] + 1; pos < index; ++pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos - i] = elements[pos];
</s> add trailingIndex = indicesToMove[indicesToMove.length - 1];
} else {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
trailingIndex = elements.indexOf(groupElements[groupElements.length - 1]);
} else {
trailingIndex = elements.length - 1; </s> remove export const moveOneLeft = <T>(elements: T[], indicesToMove: number[]) => {
indicesToMove.sort((a: number, b: number) => a - b);
let isSorted = true;
// We go from left to right to avoid overriding the wrong elements
indicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === i;
if (isSorted) {
return;
</s> add /**
* Returns indices of elements to move based on selected elements.
* Includes contiguous deleted elements that are between two selected elements,
* e.g.: [0 (selected), 1 (deleted), 2 (deleted), 3 (selected)]
*/
const getIndicesToMove = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
let selectedIndices: number[] = [];
let deletedIndices: number[] = [];
let includeDeletedIndex = null;
let i = -1;
while (++i < elements.length) {
if (appState.selectedElementIds[elements[i].id]) {
if (deletedIndices.length) {
selectedIndices = selectedIndices.concat(deletedIndices);
deletedIndices = [];
}
selectedIndices.push(i);
includeDeletedIndex = i + 1;
} else if (elements[i].isDeleted && includeDeletedIndex === i) {
includeDeletedIndex = i + 1;
deletedIndices.push(i);
} else {
deletedIndices = []; </s> remove // We go from the next marker to the right (i - 1) to the current one (index)
for (let pos = reversedIndicesToMove[i - 1] - 1; pos >= index; --pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos + i] = elements[pos];
}
});
</s> add const leadingElements =
direction === "left"
? elements.slice(0, targetIndex)
: elements.slice(0, leadingIndex);
const targetElements = elements.slice(leadingIndex, trailingIndex + 1);
const displacedElements =
direction === "left"
? elements.slice(targetIndex, leadingIndex)
: elements.slice(trailingIndex + 1, targetIndex + 1);
const trailingElements =
direction === "left"
? elements.slice(trailingIndex + 1)
: elements.slice(targetIndex + 1);
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/actions/actionDuplicateSelection.tsx
|
keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep replace replace replace replace keep keep keep keep
|
<mask> const oldIdToDuplicatedId = new Map();
<mask> const finalElements = elements.reduce(
<mask> (acc: Array<ExcalidrawElement>, element: ExcalidrawElement) => {
<mask> if (appState.selectedElementIds[element.id]) {
<mask> const newElement = duplicateElement(
<mask> appState.editingGroupId,
<mask> groupIdMap,
<mask> element,
<mask> {
<mask> x: element.x + 10,
<mask> y: element.y + 10,
<mask> },
<mask> );
<mask> oldIdToDuplicatedId.set(element.id, newElement.id);
<mask> oldElements.push(element);
<mask> newElements.push(newElement);
<mask> return acc.concat([element, newElement]);
<mask> }
<mask> return acc.concat(element);
<mask> },
<mask> [],
<mask> );
<mask> fixBindingsAfterDuplication(finalElements, oldElements, oldIdToDuplicatedId);
<mask> return {
<mask> elements: finalElements,
<mask> appState: selectGroupsForSelectedElements(
</s> fix zindex to account for group boundaries (#2065) </s> remove export const moveOneRight = <T>(elements: T[], indicesToMove: number[]) => {
const reversedIndicesToMove = indicesToMove.sort(
(a: number, b: number) => b - a,
);
let isSorted = true;
// We go from right to left to avoid overriding the wrong elements
reversedIndicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === elements.length - i - 1;
if (isSorted) {
return;
</s> add /**
* Returns next candidate index that's available to be moved to. Currently that
* is a non-deleted element, and not inside a group (unless we're editing it).
*/
const getTargetIndex = (
appState: AppState,
elements: ExcalidrawElement[],
boundaryIndex: number,
direction: "left" | "right",
) => {
const sourceElement = elements[boundaryIndex];
const indexFilter = (element: ExcalidrawElement) => {
if (element.isDeleted) {
return false; </s> remove return elements;
</s> add for (let index = leadingIndex; index < trailingIndex + 1; index++) {
if (indicesToMove.includes(index)) {
targetElements.push(elements[index]);
} else {
displacedElements.push(elements[index]);
}
}
const leadingElements = elements.slice(0, leadingIndex);
const trailingElements = elements.slice(trailingIndex + 1);
return direction === "left"
? [
...leadingElements,
...targetElements,
...displacedElements,
...trailingElements,
]
: [
...leadingElements,
...displacedElements,
...targetElements,
...trailingElements,
];
};
// public API
// -----------------------------------------------------------------------------
export const moveOneLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "left");
};
export const moveOneRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "right");
};
export const moveAllLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "left");
};
export const moveAllRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "right"); </s> remove return !!element.groupIds
</s> add return getSelectedGroupForElement(appState, element) != null;
}
export const getSelectedGroupForElement = (
appState: AppState,
element: ExcalidrawElement,
) => {
return element.groupIds </s> remove // We go from the next marker to the left (i - 1) to the current one (index)
for (let pos = indicesToMove[i - 1] + 1; pos < index; ++pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos - i] = elements[pos];
</s> add trailingIndex = indicesToMove[indicesToMove.length - 1];
} else {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
trailingIndex = elements.indexOf(groupElements[groupElements.length - 1]);
} else {
trailingIndex = elements.length - 1; </s> remove h.elements = elements.map(({ id, isDeleted = false, isSelected = false }) => {
const element = API.createElement({ type: "rectangle", id, isDeleted });
if (isSelected) {
selectedElementIds[element.id] = true;
}
return element;
});
</s> add h.elements = elements.map(
({
id,
isDeleted = false,
isSelected = false,
groupIds = [],
y = 100,
x = 100,
width = 100,
height = 100,
}) => {
const element = API.createElement({
type: "rectangle",
id,
isDeleted,
x,
y,
width,
height,
});
// @ts-ignore
element.groupIds = groupIds;
if (isSelected) {
selectedElementIds[element.id] = true;
}
return element;
},
);
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/actions/actionDuplicateSelection.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> export const actionSendBackward = register({
<mask> name: "sendBackward",
<mask> perform: (elements, appState) => {
<mask> return {
<mask> elements: moveElements(moveOneLeft, elements, appState),
<mask> appState,
<mask> commitToHistory: true,
<mask> };
<mask> },
<mask> contextItemLabel: "labels.sendBackward",
</s> fix zindex to account for group boundaries (#2065) </s> remove elements: moveElements(moveOneRight, elements, appState),
</s> add elements: moveOneRight(elements, appState), </s> remove elements: moveElements(moveAllLeft, elements, appState),
</s> add elements: moveAllLeft(elements, appState), </s> remove elements: moveElements(moveAllRight, elements, appState),
</s> add elements: moveAllRight(elements, appState), </s> remove return elements;
</s> add for (let index = leadingIndex; index < trailingIndex + 1; index++) {
if (indicesToMove.includes(index)) {
targetElements.push(elements[index]);
} else {
displacedElements.push(elements[index]);
}
}
const leadingElements = elements.slice(0, leadingIndex);
const trailingElements = elements.slice(trailingIndex + 1);
return direction === "left"
? [
...leadingElements,
...targetElements,
...displacedElements,
...trailingElements,
]
: [
...leadingElements,
...displacedElements,
...targetElements,
...trailingElements,
];
};
// public API
// -----------------------------------------------------------------------------
export const moveOneLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "left");
};
export const moveOneRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "right");
};
export const moveAllLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "left");
};
export const moveAllRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "right"); </s> add appState, </s> remove swap(elements, index - 1, index);
});
</s> add }
return selectedIndices;
};
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/actions/actionZindex.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> export const actionBringForward = register({
<mask> name: "bringForward",
<mask> perform: (elements, appState) => {
<mask> return {
<mask> elements: moveElements(moveOneRight, elements, appState),
<mask> appState,
<mask> commitToHistory: true,
<mask> };
<mask> },
<mask> contextItemLabel: "labels.bringForward",
</s> fix zindex to account for group boundaries (#2065) </s> remove elements: moveElements(moveOneLeft, elements, appState),
</s> add elements: moveOneLeft(elements, appState), </s> remove elements: moveElements(moveAllLeft, elements, appState),
</s> add elements: moveAllLeft(elements, appState), </s> remove elements: moveElements(moveAllRight, elements, appState),
</s> add elements: moveAllRight(elements, appState), </s> remove return elements;
</s> add for (let index = leadingIndex; index < trailingIndex + 1; index++) {
if (indicesToMove.includes(index)) {
targetElements.push(elements[index]);
} else {
displacedElements.push(elements[index]);
}
}
const leadingElements = elements.slice(0, leadingIndex);
const trailingElements = elements.slice(trailingIndex + 1);
return direction === "left"
? [
...leadingElements,
...targetElements,
...displacedElements,
...trailingElements,
]
: [
...leadingElements,
...displacedElements,
...targetElements,
...trailingElements,
];
};
// public API
// -----------------------------------------------------------------------------
export const moveOneLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "left");
};
export const moveOneRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "right");
};
export const moveAllLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "left");
};
export const moveAllRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "right"); </s> add appState, </s> remove swap(elements, index - 1, index);
});
</s> add }
return selectedIndices;
};
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/actions/actionZindex.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> export const actionSendToBack = register({
<mask> name: "sendToBack",
<mask> perform: (elements, appState) => {
<mask> return {
<mask> elements: moveElements(moveAllLeft, elements, appState),
<mask> appState,
<mask> commitToHistory: true,
<mask> };
<mask> },
<mask> contextItemLabel: "labels.sendToBack",
</s> fix zindex to account for group boundaries (#2065) </s> remove elements: moveElements(moveOneLeft, elements, appState),
</s> add elements: moveOneLeft(elements, appState), </s> remove elements: moveElements(moveOneRight, elements, appState),
</s> add elements: moveOneRight(elements, appState), </s> remove elements: moveElements(moveAllRight, elements, appState),
</s> add elements: moveAllRight(elements, appState), </s> remove return elements;
</s> add for (let index = leadingIndex; index < trailingIndex + 1; index++) {
if (indicesToMove.includes(index)) {
targetElements.push(elements[index]);
} else {
displacedElements.push(elements[index]);
}
}
const leadingElements = elements.slice(0, leadingIndex);
const trailingElements = elements.slice(trailingIndex + 1);
return direction === "left"
? [
...leadingElements,
...targetElements,
...displacedElements,
...trailingElements,
]
: [
...leadingElements,
...displacedElements,
...targetElements,
...trailingElements,
];
};
// public API
// -----------------------------------------------------------------------------
export const moveOneLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "left");
};
export const moveOneRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "right");
};
export const moveAllLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "left");
};
export const moveAllRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "right"); </s> add appState, </s> remove swap(elements, index - 1, index);
});
</s> add }
return selectedIndices;
};
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/actions/actionZindex.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> export const actionBringToFront = register({
<mask> name: "bringToFront",
<mask> perform: (elements, appState) => {
<mask> return {
<mask> elements: moveElements(moveAllRight, elements, appState),
<mask> appState,
<mask> commitToHistory: true,
<mask> };
<mask> },
<mask> contextItemLabel: "labels.bringToFront",
</s> fix zindex to account for group boundaries (#2065) </s> remove elements: moveElements(moveOneLeft, elements, appState),
</s> add elements: moveOneLeft(elements, appState), </s> remove elements: moveElements(moveOneRight, elements, appState),
</s> add elements: moveOneRight(elements, appState), </s> remove elements: moveElements(moveAllLeft, elements, appState),
</s> add elements: moveAllLeft(elements, appState), </s> remove return elements;
</s> add for (let index = leadingIndex; index < trailingIndex + 1; index++) {
if (indicesToMove.includes(index)) {
targetElements.push(elements[index]);
} else {
displacedElements.push(elements[index]);
}
}
const leadingElements = elements.slice(0, leadingIndex);
const trailingElements = elements.slice(trailingIndex + 1);
return direction === "left"
? [
...leadingElements,
...targetElements,
...displacedElements,
...trailingElements,
]
: [
...leadingElements,
...displacedElements,
...targetElements,
...trailingElements,
];
};
// public API
// -----------------------------------------------------------------------------
export const moveOneLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "left");
};
export const moveOneRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "right");
};
export const moveAllLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "left");
};
export const moveAllRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "right"); </s> add appState, </s> remove swap(elements, index - 1, index);
});
</s> add }
return selectedIndices;
};
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/actions/actionZindex.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> element: TElement,
<mask> overrides?: Partial<TElement>,
<mask> ): TElement => {
<mask> let copy: TElement = deepCopyElement(element);
<mask> copy.id = randomId();
<mask> copy.seed = randomInteger();
<mask> copy.groupIds = getNewGroupIdsForDuplication(
<mask> copy.groupIds,
<mask> editingGroupId,
<mask> (groupId) => {
</s> fix zindex to account for group boundaries (#2065) </s> remove const finalElements = elements.reduce(
(acc: Array<ExcalidrawElement>, element: ExcalidrawElement) => {
if (appState.selectedElementIds[element.id]) {
const newElement = duplicateElement(
appState.editingGroupId,
groupIdMap,
element,
{
x: element.x + 10,
y: element.y + 10,
},
);
oldIdToDuplicatedId.set(element.id, newElement.id);
oldElements.push(element);
newElements.push(newElement);
return acc.concat([element, newElement]);
</s> add const duplicateAndOffsetElement = (element: ExcalidrawElement) => {
const newElement = duplicateElement(
appState.editingGroupId,
groupIdMap,
element,
{
x: element.x + 10,
y: element.y + 10,
},
);
oldIdToDuplicatedId.set(element.id, newElement.id);
oldElements.push(element);
newElements.push(newElement);
return newElement;
};
const finalElements: ExcalidrawElement[] = [];
let i = 0;
while (i < elements.length) {
const element = elements[i];
if (appState.selectedElementIds[element.id]) {
if (element.groupIds.length) {
const groupId = getSelectedGroupForElement(appState, element);
// if group selected, duplicate it atomically
if (groupId) {
const groupElements = getElementsInGroup(elements, groupId);
finalElements.push(
...groupElements,
...groupElements.map((element) =>
duplicateAndOffsetElement(element),
),
);
i = i + groupElements.length;
continue;
} </s> remove return !!element.groupIds
</s> add return getSelectedGroupForElement(appState, element) != null;
}
export const getSelectedGroupForElement = (
appState: AppState,
element: ExcalidrawElement,
) => {
return element.groupIds </s> remove export const moveOneLeft = <T>(elements: T[], indicesToMove: number[]) => {
indicesToMove.sort((a: number, b: number) => a - b);
let isSorted = true;
// We go from left to right to avoid overriding the wrong elements
indicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === i;
if (isSorted) {
return;
</s> add /**
* Returns indices of elements to move based on selected elements.
* Includes contiguous deleted elements that are between two selected elements,
* e.g.: [0 (selected), 1 (deleted), 2 (deleted), 3 (selected)]
*/
const getIndicesToMove = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
let selectedIndices: number[] = [];
let deletedIndices: number[] = [];
let includeDeletedIndex = null;
let i = -1;
while (++i < elements.length) {
if (appState.selectedElementIds[elements[i].id]) {
if (deletedIndices.length) {
selectedIndices = selectedIndices.concat(deletedIndices);
deletedIndices = [];
}
selectedIndices.push(i);
includeDeletedIndex = i + 1;
} else if (elements[i].isDeleted && includeDeletedIndex === i) {
includeDeletedIndex = i + 1;
deletedIndices.push(i);
} else {
deletedIndices = []; </s> remove const swap = <T>(elements: T[], indexA: number, indexB: number) => {
const element = elements[indexA];
elements[indexA] = elements[indexB];
elements[indexB] = element;
};
</s> add import { AppState } from "./types";
import { ExcalidrawElement } from "./element/types";
import { getElementsInGroup } from "./groups";
import { findLastIndex, findIndex } from "./utils"; </s> remove return elements;
</s> add const toContiguousGroups = (array: number[]) => {
let cursor = 0;
return array.reduce((acc, value, index) => {
if (index > 0 && array[index - 1] !== value - 1) {
cursor = ++cursor;
}
(acc[cursor] || (acc[cursor] = [])).push(value);
return acc;
}, [] as number[][]); </s> remove export const moveOneRight = <T>(elements: T[], indicesToMove: number[]) => {
const reversedIndicesToMove = indicesToMove.sort(
(a: number, b: number) => b - a,
);
let isSorted = true;
// We go from right to left to avoid overriding the wrong elements
reversedIndicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === elements.length - i - 1;
if (isSorted) {
return;
</s> add /**
* Returns next candidate index that's available to be moved to. Currently that
* is a non-deleted element, and not inside a group (unless we're editing it).
*/
const getTargetIndex = (
appState: AppState,
elements: ExcalidrawElement[],
boundaryIndex: number,
direction: "left" | "right",
) => {
const sourceElement = elements[boundaryIndex];
const indexFilter = (element: ExcalidrawElement) => {
if (element.isDeleted) {
return false;
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/element/newElement.ts
|
keep replace keep keep replace keep keep
|
<mask> ) {
<mask> return !!element.groupIds
<mask> .filter((groupId) => groupId !== appState.editingGroupId)
<mask> .find((groupId) => appState.selectedGroupIds[groupId]);
<mask> }
<mask>
<mask> export function getSelectedGroupIds(appState: AppState): GroupId[] {
</s> fix zindex to account for group boundaries (#2065) </s> remove return elements;
</s> add for (let index = leadingIndex; index < trailingIndex + 1; index++) {
if (indicesToMove.includes(index)) {
targetElements.push(elements[index]);
} else {
displacedElements.push(elements[index]);
}
}
const leadingElements = elements.slice(0, leadingIndex);
const trailingElements = elements.slice(trailingIndex + 1);
return direction === "left"
? [
...leadingElements,
...targetElements,
...displacedElements,
...trailingElements,
]
: [
...leadingElements,
...displacedElements,
...targetElements,
...trailingElements,
];
};
// public API
// -----------------------------------------------------------------------------
export const moveOneLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "left");
};
export const moveOneRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "right");
};
export const moveAllLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "left");
};
export const moveAllRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "right"); </s> remove return elements;
</s> add const toContiguousGroups = (array: number[]) => {
let cursor = 0;
return array.reduce((acc, value, index) => {
if (index > 0 && array[index - 1] !== value - 1) {
cursor = ++cursor;
}
(acc[cursor] || (acc[cursor] = [])).push(value);
return acc;
}, [] as number[][]); </s> remove swap(elements, index - 1, index);
});
</s> add }
return selectedIndices;
}; </s> remove const finalElements = elements.reduce(
(acc: Array<ExcalidrawElement>, element: ExcalidrawElement) => {
if (appState.selectedElementIds[element.id]) {
const newElement = duplicateElement(
appState.editingGroupId,
groupIdMap,
element,
{
x: element.x + 10,
y: element.y + 10,
},
);
oldIdToDuplicatedId.set(element.id, newElement.id);
oldElements.push(element);
newElements.push(newElement);
return acc.concat([element, newElement]);
</s> add const duplicateAndOffsetElement = (element: ExcalidrawElement) => {
const newElement = duplicateElement(
appState.editingGroupId,
groupIdMap,
element,
{
x: element.x + 10,
y: element.y + 10,
},
);
oldIdToDuplicatedId.set(element.id, newElement.id);
oldElements.push(element);
newElements.push(newElement);
return newElement;
};
const finalElements: ExcalidrawElement[] = [];
let i = 0;
while (i < elements.length) {
const element = elements[i];
if (appState.selectedElementIds[element.id]) {
if (element.groupIds.length) {
const groupId = getSelectedGroupForElement(appState, element);
// if group selected, duplicate it atomically
if (groupId) {
const groupElements = getElementsInGroup(elements, groupId);
finalElements.push(
...groupElements,
...groupElements.map((element) =>
duplicateAndOffsetElement(element),
),
);
i = i + groupElements.length;
continue;
} </s> remove import { selectGroupsForSelectedElements } from "../groups";
</s> add import {
selectGroupsForSelectedElements,
getSelectedGroupForElement,
getElementsInGroup,
} from "../groups";
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/groups.ts
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> "boundElementIds": null,
<mask> "fillStyle": "hachure",
<mask> "groupIds": Array [],
<mask> "height": 50,
<mask> "id": "id2",
<mask> "isDeleted": false,
<mask> "opacity": 100,
<mask> "roughness": 1,
<mask> "seed": 401146281,
<mask> "strokeColor": "#000000",
</s> fix zindex to account for group boundaries (#2065) </s> remove "id": "id2",
</s> add "id": "id0_copy", </s> remove "id": "id2",
</s> add "id": "id0_copy", </s> remove "id": "id1",
</s> add "id": "id0_copy", </s> remove "id": "id1",
</s> add "id": "id0_copy", </s> remove "id": "id9",
</s> add "id": "id2_copy", </s> remove "id": "id8",
</s> add "id": "id1_copy",
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/__snapshots__/move.test.tsx.snap
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> "boundElementIds": null,
<mask> "fillStyle": "hachure",
<mask> "groupIds": Array [],
<mask> "height": 10,
<mask> "id": "id2",
<mask> "isDeleted": false,
<mask> "opacity": 100,
<mask> "roughness": 1,
<mask> "seed": 401146281,
<mask> "strokeColor": "#000000",
</s> fix zindex to account for group boundaries (#2065) </s> remove "id": "id2",
</s> add "id": "id0_copy", </s> remove "id": "id2",
</s> add "id": "id0_copy", </s> remove "id": "id1",
</s> add "id": "id0_copy", </s> remove "id": "id1",
</s> add "id": "id0_copy", </s> remove "id": "id9",
</s> add "id": "id2_copy", </s> remove "id": "id8",
</s> add "id": "id1_copy",
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/__snapshots__/regressionTests.test.tsx.snap
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> "boundElementIds": null,
<mask> "fillStyle": "hachure",
<mask> "groupIds": Array [],
<mask> "height": 10,
<mask> "id": "id2",
<mask> "isDeleted": false,
<mask> "opacity": 100,
<mask> "roughness": 1,
<mask> "seed": 401146281,
<mask> "strokeColor": "#000000",
</s> fix zindex to account for group boundaries (#2065)
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/__snapshots__/regressionTests.test.tsx.snap
|
keep replace keep keep replace keep keep keep
|
<mask> "groupIds": Array [
<mask> "id7",
<mask> ],
<mask> "height": 10,
<mask> "id": "id6",
<mask> "isDeleted": false,
<mask> "opacity": 100,
<mask> "roughness": 1,
</s> fix zindex to account for group boundaries (#2065) </s> remove "id": "id6",
</s> add "id": "id0_copy", </s> remove "id": "id9",
</s> add "id": "id2_copy", </s> remove "id": "id8",
</s> add "id": "id1_copy", </s> remove "id": "id9",
</s> add "id": "id2_copy", </s> remove "id": "id8",
</s> add "id": "id1_copy",
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/__snapshots__/regressionTests.test.tsx.snap
|
keep replace keep keep replace keep keep keep
|
<mask> "groupIds": Array [
<mask> "id7",
<mask> ],
<mask> "height": 10,
<mask> "id": "id8",
<mask> "isDeleted": false,
<mask> "opacity": 100,
<mask> "roughness": 1,
</s> fix zindex to account for group boundaries (#2065) </s> remove "id": "id8",
</s> add "id": "id1_copy", </s> remove "id": "id9",
</s> add "id": "id2_copy", </s> remove "id": "id9",
</s> add "id": "id2_copy", </s> remove "id": "id6",
</s> add "id": "id0_copy", </s> remove "id": "id6",
</s> add "id": "id0_copy",
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/__snapshots__/regressionTests.test.tsx.snap
|
keep replace keep keep replace keep keep keep
|
<mask> "groupIds": Array [
<mask> "id7",
<mask> ],
<mask> "height": 10,
<mask> "id": "id9",
<mask> "isDeleted": false,
<mask> "opacity": 100,
<mask> "roughness": 1,
</s> fix zindex to account for group boundaries (#2065) </s> remove "id": "id9",
</s> add "id": "id2_copy", </s> remove "id": "id8",
</s> add "id": "id1_copy", </s> remove "id": "id8",
</s> add "id": "id1_copy", </s> remove "id": "id6",
</s> add "id": "id0_copy", </s> remove "id": "id6",
</s> add "id": "id0_copy",
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/__snapshots__/regressionTests.test.tsx.snap
|
keep replace keep keep replace
|
<mask> "groupIds": Array [
<mask> "id7",
<mask> ],
<mask> "height": 10,
<mask> "id": "id6",
</s> fix zindex to account for group boundaries (#2065)
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/__snapshots__/regressionTests.test.tsx.snap
|
keep keep replace keep keep replace
|
<mask> "fillStyle": "hachure",
<mask> "groupIds": Array [
<mask> "id7",
<mask> ],
<mask> "height": 10,
<mask> "id": "id8",
</s> fix zindex to account for group boundaries (#2065)
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/__snapshots__/regressionTests.test.tsx.snap
|
keep keep keep replace keep keep replace keep keep keep keep
|
<mask> "boundElementIds": null,
<mask> "fillStyle": "hachure",
<mask> "groupIds": Array [
<mask> "id7",
<mask> ],
<mask> "height": 10,
<mask> "id": "id9",
<mask> "isDeleted": false,
<mask> "opacity": 100,
<mask> "roughness": 1,
<mask> "seed": 760410951,
</s> fix zindex to account for group boundaries (#2065)
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/__snapshots__/regressionTests.test.tsx.snap
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> "scrollX": 0,
<mask> "scrollY": 0,
<mask> "scrolledOutside": false,
<mask> "selectedElementIds": Object {
<mask> "id1": true,
<mask> },
<mask> "selectedGroupIds": Object {},
<mask> "selectionElement": null,
<mask> "shouldAddWatermark": false,
<mask> "shouldCacheIgnoreZoom": false,
</s> fix zindex to account for group boundaries (#2065) </s> remove "id1": true,
</s> add "id0_copy": true, </s> remove elements: moveElements(moveOneLeft, elements, appState),
</s> add elements: moveOneLeft(elements, appState), </s> remove elements: moveElements(moveOneRight, elements, appState),
</s> add elements: moveOneRight(elements, appState), </s> remove elements: moveElements(moveAllLeft, elements, appState),
</s> add elements: moveAllLeft(elements, appState), </s> remove elements: moveElements(moveAllRight, elements, appState),
</s> add elements: moveAllRight(elements, appState), </s> remove "id7",
</s> add "id6",
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/__snapshots__/regressionTests.test.tsx.snap
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> "boundElementIds": null,
<mask> "fillStyle": "hachure",
<mask> "groupIds": Array [],
<mask> "height": 20,
<mask> "id": "id1",
<mask> "isDeleted": false,
<mask> "opacity": 100,
<mask> "roughness": 1,
<mask> "seed": 449462985,
<mask> "strokeColor": "#000000",
</s> fix zindex to account for group boundaries (#2065) </s> remove "id": "id1",
</s> add "id": "id0_copy", </s> remove "id": "id2",
</s> add "id": "id0_copy", </s> remove "id": "id2",
</s> add "id": "id0_copy", </s> remove "id": "id2",
</s> add "id": "id0_copy", </s> remove "id": "id8",
</s> add "id": "id1_copy", </s> remove "id": "id6",
</s> add "id": "id0_copy",
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/__snapshots__/regressionTests.test.tsx.snap
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> "editingGroupId": null,
<mask> "editingLinearElement": null,
<mask> "name": "Untitled-201933152653",
<mask> "selectedElementIds": Object {
<mask> "id1": true,
<mask> },
<mask> "viewBackgroundColor": "#ffffff",
<mask> },
<mask> "elements": Array [
<mask> Object {
</s> fix zindex to account for group boundaries (#2065) </s> remove "id1": true,
</s> add "id0_copy": true, </s> remove elements: moveElements(moveOneLeft, elements, appState),
</s> add elements: moveOneLeft(elements, appState), </s> remove elements: moveElements(moveOneRight, elements, appState),
</s> add elements: moveOneRight(elements, appState), </s> remove elements: moveElements(moveAllLeft, elements, appState),
</s> add elements: moveAllLeft(elements, appState), </s> remove elements: moveElements(moveAllRight, elements, appState),
</s> add elements: moveAllRight(elements, appState), </s> add { id: "0" },
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/__snapshots__/regressionTests.test.tsx.snap
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> "boundElementIds": null,
<mask> "fillStyle": "hachure",
<mask> "groupIds": Array [],
<mask> "height": 20,
<mask> "id": "id1",
<mask> "isDeleted": false,
<mask> "opacity": 100,
<mask> "roughness": 1,
<mask> "seed": 449462985,
<mask> "strokeColor": "#000000",
</s> fix zindex to account for group boundaries (#2065)
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/__snapshots__/regressionTests.test.tsx.snap
|
keep keep keep add keep keep keep keep
|
<mask> actionSendBackward,
<mask> actionBringForward,
<mask> actionBringToFront,
<mask> actionSendToBack,
<mask> } from "../actions";
<mask> import { AppState } from "../types";
<mask> import { API } from "./helpers/api";
<mask>
</s> fix zindex to account for group boundaries (#2065) </s> add import { AppState } from "../types"; </s> remove import { selectGroupsForSelectedElements } from "../groups";
</s> add import {
selectGroupsForSelectedElements,
getSelectedGroupForElement,
getElementsInGroup,
} from "../groups"; </s> remove const swap = <T>(elements: T[], indexA: number, indexB: number) => {
const element = elements[indexA];
elements[indexA] = elements[indexB];
elements[indexB] = element;
};
</s> add import { AppState } from "./types";
import { ExcalidrawElement } from "./element/types";
import { getElementsInGroup } from "./groups";
import { findLastIndex, findIndex } from "./utils"; </s> remove // We go from the next marker to the left (i - 1) to the current one (index)
for (let pos = indicesToMove[i - 1] + 1; pos < index; ++pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos - i] = elements[pos];
</s> add trailingIndex = indicesToMove[indicesToMove.length - 1];
} else {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
trailingIndex = elements.indexOf(groupElements[groupElements.length - 1]);
} else {
trailingIndex = elements.length - 1; </s> remove export const moveOneLeft = <T>(elements: T[], indicesToMove: number[]) => {
indicesToMove.sort((a: number, b: number) => a - b);
let isSorted = true;
// We go from left to right to avoid overriding the wrong elements
indicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === i;
if (isSorted) {
return;
</s> add /**
* Returns indices of elements to move based on selected elements.
* Includes contiguous deleted elements that are between two selected elements,
* e.g.: [0 (selected), 1 (deleted), 2 (deleted), 3 (selected)]
*/
const getIndicesToMove = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
let selectedIndices: number[] = [];
let deletedIndices: number[] = [];
let includeDeletedIndex = null;
let i = -1;
while (++i < elements.length) {
if (appState.selectedElementIds[elements[i].id]) {
if (deletedIndices.length) {
selectedIndices = selectedIndices.concat(deletedIndices);
deletedIndices = [];
}
selectedIndices.push(i);
includeDeletedIndex = i + 1;
} else if (elements[i].isDeleted && includeDeletedIndex === i) {
includeDeletedIndex = i + 1;
deletedIndices.push(i);
} else {
deletedIndices = []; </s> remove // We go from the next marker to the right (i - 1) to the current one (index)
for (let pos = reversedIndicesToMove[i - 1] - 1; pos >= index; --pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos + i] = elements[pos];
}
});
</s> add const leadingElements =
direction === "left"
? elements.slice(0, targetIndex)
: elements.slice(0, leadingIndex);
const targetElements = elements.slice(leadingIndex, trailingIndex + 1);
const displacedElements =
direction === "left"
? elements.slice(targetIndex, leadingIndex)
: elements.slice(trailingIndex + 1, targetIndex + 1);
const trailingElements =
direction === "left"
? elements.slice(trailingIndex + 1)
: elements.slice(targetIndex + 1);
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep add keep keep keep keep
|
<mask> actionSendToBack,
<mask> actionDuplicateSelection,
<mask> } from "../actions";
<mask> import { API } from "./helpers/api";
<mask>
<mask> // Unmount ReactDOM from root
<mask> ReactDOM.unmountComponentAtNode(document.getElementById("root")!);
</s> fix zindex to account for group boundaries (#2065) </s> add actionDuplicateSelection, </s> remove import { selectGroupsForSelectedElements } from "../groups";
</s> add import {
selectGroupsForSelectedElements,
getSelectedGroupForElement,
getElementsInGroup,
} from "../groups"; </s> remove const swap = <T>(elements: T[], indexA: number, indexB: number) => {
const element = elements[indexA];
elements[indexA] = elements[indexB];
elements[indexB] = element;
};
</s> add import { AppState } from "./types";
import { ExcalidrawElement } from "./element/types";
import { getElementsInGroup } from "./groups";
import { findLastIndex, findIndex } from "./utils"; </s> remove // We go from the next marker to the left (i - 1) to the current one (index)
for (let pos = indicesToMove[i - 1] + 1; pos < index; ++pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos - i] = elements[pos];
</s> add trailingIndex = indicesToMove[indicesToMove.length - 1];
} else {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
trailingIndex = elements.indexOf(groupElements[groupElements.length - 1]);
} else {
trailingIndex = elements.length - 1; </s> remove // Let's go through an example
// | |
// [a, b, c, d, e, f, g]
// -->
// [a, b, d, e, g, c, f]
//
// We are going to override all the elements we want to move, so we keep them in an array
// that we will restore at the end.
// [c, f]
//
// From now on, we'll never read those values from the array anymore
// |0 |1
// [a, b, _, d, e, _, g]
//
// The idea is that we want to shift all the elements between the marker 0 and 1
// by one slot to the left.
//
// |0 |1
// [a, b, _, d, e, _, g]
// <- <-
//
// which gives us
//
// |0 |1
// [a, b, d, e, _, _, g]
//
// Now, we need to move all the elements from marker 1 to the end by two (not one)
// slots to the left, which gives us
//
// |0 |1
// [a, b, d, e, _, _, g]
// ^------
//
// which gives us
//
// |0 |1
// [a, b, d, e, g, _, _]
//
// At this point, we can fill back the rightmost elements with the array we saved at
// the beginning
//
// |0 |1
// [a, b, d, e, g, c, f]
//
// And we are done!
export const moveAllRight = <T>(elements: T[], indicesToMove: number[]) => {
const reversedIndicesToMove = indicesToMove.sort(
(a: number, b: number) => b - a,
);
// Copy the elements to move
const rightMostElements = reversedIndicesToMove.map(
(index) => elements[index],
);
indicesToMove = reversedIndicesToMove
// We go from left to right to avoid overriding elements.
.reverse()
// We last element index for the final marker
.concat([elements.length]);
indicesToMove.forEach((index, i) => {
// We skip the first one as it is not paired with anything else
if (i === 0) {
return;
</s> add const shiftElementsToEnd = (
elements: readonly ExcalidrawElement[],
appState: AppState,
direction: "left" | "right",
) => {
const indicesToMove = getIndicesToMove(elements, appState);
const targetElements: ExcalidrawElement[] = [];
const displacedElements: ExcalidrawElement[] = [];
let leadingIndex, trailingIndex;
if (direction === "left") {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
leadingIndex = elements.indexOf(groupElements[0]);
} else {
leadingIndex = 0; </s> remove // Let's go through an example
// | |
// [a, b, c, d, e, f, g]
// -->
// [c, f, a, b, d, e, g]
//
// We are going to override all the elements we want to move, so we keep them in an array
// that we will restore at the end.
// [c, f]
//
// From now on, we'll never read those values from the array anymore
// |1 |0
// [a, b, _, d, e, _, g]
//
// The idea is that we want to shift all the elements between the marker 0 and 1
// by one slot to the right.
//
// |1 |0
// [a, b, _, d, e, _, g]
// -> ->
//
// which gives us
//
// |1 |0
// [a, b, _, _, d, e, g]
//
// Now, we need to move all the elements from marker 1 to the beginning by two (not one)
// slots to the right, which gives us
//
// |1 |0
// [a, b, _, _, d, e, g]
// ---|--^ ^
// ------|
//
// which gives us
//
// |1 |0
// [_, _, a, b, d, e, g]
//
// At this point, we can fill back the leftmost elements with the array we saved at
// the beginning
//
// |1 |0
// [c, f, a, b, d, e, g]
//
// And we are done!
export const moveAllLeft = <T>(elements: T[], indicesToMove: number[]) => {
indicesToMove.sort((a: number, b: number) => a - b);
// Copy the elements to move
const leftMostElements = indicesToMove.map((index) => elements[index]);
const reversedIndicesToMove = indicesToMove
// We go from right to left to avoid overriding elements.
.reverse()
// We add 0 for the final marker
.concat([0]);
reversedIndicesToMove.forEach((index, i) => {
// We skip the first one as it is not paired with anything else
if (i === 0) {
</s> add const shiftElements = (
appState: AppState,
elements: ExcalidrawElement[],
direction: "left" | "right",
) => {
const indicesToMove = getIndicesToMove(elements, appState);
let groupedIndices = toContiguousGroups(indicesToMove);
if (direction === "right") {
groupedIndices = groupedIndices.reverse();
}
groupedIndices.forEach((indices, i) => {
const leadingIndex = indices[0];
const trailingIndex = indices[indices.length - 1];
const boundaryIndex = direction === "left" ? leadingIndex : trailingIndex;
const targetIndex = getTargetIndex(
appState,
elements,
boundaryIndex,
direction,
);
if (targetIndex === -1 || boundaryIndex === targetIndex) {
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep replace keep keep keep replace replace replace replace replace replace replace keep keep
|
<mask> const { h } = window;
<mask>
<mask> const populateElements = (
<mask> elements: { id: string; isDeleted?: boolean; isSelected?: boolean }[],
<mask> ) => {
<mask> const selectedElementIds: any = {};
<mask>
<mask> h.elements = elements.map(({ id, isDeleted = false, isSelected = false }) => {
<mask> const element = API.createElement({ type: "rectangle", id, isDeleted });
<mask> if (isSelected) {
<mask> selectedElementIds[element.id] = true;
<mask> }
<mask> return element;
<mask> });
<mask>
<mask> h.setState({
</s> fix zindex to account for group boundaries (#2065) </s> remove elements: { id: string; isDeleted?: true; isSelected?: true }[];
</s> add elements: {
id: string;
isDeleted?: true;
isSelected?: true;
groupIds?: string[];
}[];
appState?: Partial<AppState>; </s> add appState, </s> remove return elements;
</s> add for (let index = leadingIndex; index < trailingIndex + 1; index++) {
if (indicesToMove.includes(index)) {
targetElements.push(elements[index]);
} else {
displacedElements.push(elements[index]);
}
}
const leadingElements = elements.slice(0, leadingIndex);
const trailingElements = elements.slice(trailingIndex + 1);
return direction === "left"
? [
...leadingElements,
...targetElements,
...displacedElements,
...trailingElements,
]
: [
...leadingElements,
...displacedElements,
...targetElements,
...trailingElements,
];
};
// public API
// -----------------------------------------------------------------------------
export const moveOneLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "left");
};
export const moveOneRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "right");
};
export const moveAllLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "left");
};
export const moveAllRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "right"); </s> remove const swap = <T>(elements: T[], indexA: number, indexB: number) => {
const element = elements[indexA];
elements[indexA] = elements[indexB];
elements[indexB] = element;
};
</s> add import { AppState } from "./types";
import { ExcalidrawElement } from "./element/types";
import { getElementsInGroup } from "./groups";
import { findLastIndex, findIndex } from "./utils"; </s> remove const finalElements = elements.reduce(
(acc: Array<ExcalidrawElement>, element: ExcalidrawElement) => {
if (appState.selectedElementIds[element.id]) {
const newElement = duplicateElement(
appState.editingGroupId,
groupIdMap,
element,
{
x: element.x + 10,
y: element.y + 10,
},
);
oldIdToDuplicatedId.set(element.id, newElement.id);
oldElements.push(element);
newElements.push(newElement);
return acc.concat([element, newElement]);
</s> add const duplicateAndOffsetElement = (element: ExcalidrawElement) => {
const newElement = duplicateElement(
appState.editingGroupId,
groupIdMap,
element,
{
x: element.x + 10,
y: element.y + 10,
},
);
oldIdToDuplicatedId.set(element.id, newElement.id);
oldElements.push(element);
newElements.push(newElement);
return newElement;
};
const finalElements: ExcalidrawElement[] = [];
let i = 0;
while (i < elements.length) {
const element = elements[i];
if (appState.selectedElementIds[element.id]) {
if (element.groupIds.length) {
const groupId = getSelectedGroupForElement(appState, element);
// if group selected, duplicate it atomically
if (groupId) {
const groupElements = getElementsInGroup(elements, groupId);
finalElements.push(
...groupElements,
...groupElements.map((element) =>
duplicateAndOffsetElement(element),
),
);
i = i + groupElements.length;
continue;
}
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> return element;
<mask> });
<mask>
<mask> h.setState({
<mask> ...h.state,
<mask> selectedElementIds,
<mask> });
<mask>
<mask> return selectedElementIds;
<mask> };
</s> fix zindex to account for group boundaries (#2065) </s> remove h.elements = elements.map(({ id, isDeleted = false, isSelected = false }) => {
const element = API.createElement({ type: "rectangle", id, isDeleted });
if (isSelected) {
selectedElementIds[element.id] = true;
}
return element;
});
</s> add h.elements = elements.map(
({
id,
isDeleted = false,
isSelected = false,
groupIds = [],
y = 100,
x = 100,
width = 100,
height = 100,
}) => {
const element = API.createElement({
type: "rectangle",
id,
isDeleted,
x,
y,
width,
height,
});
// @ts-ignore
element.groupIds = groupIds;
if (isSelected) {
selectedElementIds[element.id] = true;
}
return element;
},
); </s> remove // The final step
rightMostElements.forEach((element, i) => {
elements[elements.length - i - 1] = element;
});
</s> add leadingIndex = indicesToMove[0];
} </s> remove // The final step
leftMostElements.forEach((element, i) => {
elements[i] = element;
</s> add elements =
direction === "left"
? [
...leadingElements,
...targetElements,
...displacedElements,
...trailingElements,
]
: [
...leadingElements,
...displacedElements,
...targetElements,
...trailingElements,
]; </s> remove return elements;
</s> add for (let index = leadingIndex; index < trailingIndex + 1; index++) {
if (indicesToMove.includes(index)) {
targetElements.push(elements[index]);
} else {
displacedElements.push(elements[index]);
}
}
const leadingElements = elements.slice(0, leadingIndex);
const trailingElements = elements.slice(trailingIndex + 1);
return direction === "left"
? [
...leadingElements,
...targetElements,
...displacedElements,
...trailingElements,
]
: [
...leadingElements,
...displacedElements,
...targetElements,
...trailingElements,
];
};
// public API
// -----------------------------------------------------------------------------
export const moveOneLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "left");
};
export const moveOneRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "right");
};
export const moveAllLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "left");
};
export const moveAllRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "right"); </s> remove swap(elements, index - 1, index);
});
</s> add }
return selectedIndices;
}; </s> add h.setState({
editingGroupId: appState?.editingGroupId || null,
});
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep add keep keep keep keep keep keep
|
<mask> | typeof actionSendToBack;
<mask>
<mask> const assertZindex = ({
<mask> elements,
<mask> operations,
<mask> }: {
<mask> elements: {
<mask> id: string;
<mask> isDeleted?: true;
<mask> isSelected?: true;
</s> fix zindex to account for group boundaries (#2065) </s> remove elements: { id: string; isDeleted?: true; isSelected?: true }[];
</s> add elements: {
id: string;
isDeleted?: true;
isSelected?: true;
groupIds?: string[];
}[];
appState?: Partial<AppState>; </s> remove h.elements = elements.map(({ id, isDeleted = false, isSelected = false }) => {
const element = API.createElement({ type: "rectangle", id, isDeleted });
if (isSelected) {
selectedElementIds[element.id] = true;
}
return element;
});
</s> add h.elements = elements.map(
({
id,
isDeleted = false,
isSelected = false,
groupIds = [],
y = 100,
x = 100,
width = 100,
height = 100,
}) => {
const element = API.createElement({
type: "rectangle",
id,
isDeleted,
x,
y,
width,
height,
});
// @ts-ignore
element.groupIds = groupIds;
if (isSelected) {
selectedElementIds[element.id] = true;
}
return element;
},
); </s> remove elements: { id: string; isDeleted?: boolean; isSelected?: boolean }[],
</s> add elements: {
id: string;
isDeleted?: boolean;
isSelected?: boolean;
groupIds?: string[];
y?: number;
x?: number;
width?: number;
height?: number;
}[], </s> remove const swap = <T>(elements: T[], indexA: number, indexB: number) => {
const element = elements[indexA];
elements[indexA] = elements[indexB];
elements[indexB] = element;
};
</s> add import { AppState } from "./types";
import { ExcalidrawElement } from "./element/types";
import { getElementsInGroup } from "./groups";
import { findLastIndex, findIndex } from "./utils"; </s> remove export const moveOneRight = <T>(elements: T[], indicesToMove: number[]) => {
const reversedIndicesToMove = indicesToMove.sort(
(a: number, b: number) => b - a,
);
let isSorted = true;
// We go from right to left to avoid overriding the wrong elements
reversedIndicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === elements.length - i - 1;
if (isSorted) {
return;
</s> add /**
* Returns next candidate index that's available to be moved to. Currently that
* is a non-deleted element, and not inside a group (unless we're editing it).
*/
const getTargetIndex = (
appState: AppState,
elements: ExcalidrawElement[],
boundaryIndex: number,
direction: "left" | "right",
) => {
const sourceElement = elements[boundaryIndex];
const indexFilter = (element: ExcalidrawElement) => {
if (element.isDeleted) {
return false; </s> remove export const moveOneLeft = <T>(elements: T[], indicesToMove: number[]) => {
indicesToMove.sort((a: number, b: number) => a - b);
let isSorted = true;
// We go from left to right to avoid overriding the wrong elements
indicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === i;
if (isSorted) {
return;
</s> add /**
* Returns indices of elements to move based on selected elements.
* Includes contiguous deleted elements that are between two selected elements,
* e.g.: [0 (selected), 1 (deleted), 2 (deleted), 3 (selected)]
*/
const getIndicesToMove = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
let selectedIndices: number[] = [];
let deletedIndices: number[] = [];
let includeDeletedIndex = null;
let i = -1;
while (++i < elements.length) {
if (appState.selectedElementIds[elements[i].id]) {
if (deletedIndices.length) {
selectedIndices = selectedIndices.concat(deletedIndices);
deletedIndices = [];
}
selectedIndices.push(i);
includeDeletedIndex = i + 1;
} else if (elements[i].isDeleted && includeDeletedIndex === i) {
includeDeletedIndex = i + 1;
deletedIndices.push(i);
} else {
deletedIndices = [];
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> const assertZindex = ({
<mask> elements,
<mask> operations,
<mask> }: {
<mask> elements: { id: string; isDeleted?: true; isSelected?: true }[];
<mask> operations: [Actions, string[]][];
<mask> }) => {
<mask> const selectedElementIds = populateElements(elements);
<mask> operations.forEach(([action, expected]) => {
<mask> h.app.actionManager.executeAction(action);
</s> fix zindex to account for group boundaries (#2065) </s> add appState, </s> add h.setState({
editingGroupId: appState?.editingGroupId || null,
});
</s> remove elements: { id: string; isDeleted?: boolean; isSelected?: boolean }[],
</s> add elements: {
id: string;
isDeleted?: boolean;
isSelected?: boolean;
groupIds?: string[];
y?: number;
x?: number;
width?: number;
height?: number;
}[], </s> remove h.elements = elements.map(({ id, isDeleted = false, isSelected = false }) => {
const element = API.createElement({ type: "rectangle", id, isDeleted });
if (isSelected) {
selectedElementIds[element.id] = true;
}
return element;
});
</s> add h.elements = elements.map(
({
id,
isDeleted = false,
isSelected = false,
groupIds = [],
y = 100,
x = 100,
width = 100,
height = 100,
}) => {
const element = API.createElement({
type: "rectangle",
id,
isDeleted,
x,
y,
width,
height,
});
// @ts-ignore
element.groupIds = groupIds;
if (isSelected) {
selectedElementIds[element.id] = true;
}
return element;
},
); </s> remove render(<App />);
</s> add assertZindex({
elements: [
{ id: "A" },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
{ id: "D", isDeleted: true },
{ id: "E" },
],
operations: [
[actionBringForward, ["A", "D", "E", "B", "C"]],
// noop
[actionBringForward, ["A", "D", "E", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [
// noop
[actionBringForward, ["A", "B", "C"]],
],
}); </s> remove operations: [[actionSendBackward, ["A", "C", "D", "B"]]],
</s> add operations: [[actionSendBackward, ["A", "D", "B", "C"]]],
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep add keep keep keep keep
|
<mask> appState?: Partial<AppState>;
<mask> operations: [Actions, string[]][];
<mask> }) => {
<mask> const selectedElementIds = populateElements(elements);
<mask> operations.forEach(([action, expected]) => {
<mask> h.app.actionManager.executeAction(action);
<mask> expect(h.elements.map((element) => element.id)).toEqual(expected);
<mask> expect(h.state.selectedElementIds).toEqual(selectedElementIds);
</s> fix zindex to account for group boundaries (#2065) </s> remove elements: { id: string; isDeleted?: true; isSelected?: true }[];
</s> add elements: {
id: string;
isDeleted?: true;
isSelected?: true;
groupIds?: string[];
}[];
appState?: Partial<AppState>; </s> remove h.elements = elements.map(({ id, isDeleted = false, isSelected = false }) => {
const element = API.createElement({ type: "rectangle", id, isDeleted });
if (isSelected) {
selectedElementIds[element.id] = true;
}
return element;
});
</s> add h.elements = elements.map(
({
id,
isDeleted = false,
isSelected = false,
groupIds = [],
y = 100,
x = 100,
width = 100,
height = 100,
}) => {
const element = API.createElement({
type: "rectangle",
id,
isDeleted,
x,
y,
width,
height,
});
// @ts-ignore
element.groupIds = groupIds;
if (isSelected) {
selectedElementIds[element.id] = true;
}
return element;
},
); </s> remove elements: { id: string; isDeleted?: boolean; isSelected?: boolean }[],
</s> add elements: {
id: string;
isDeleted?: boolean;
isSelected?: boolean;
groupIds?: string[];
y?: number;
x?: number;
width?: number;
height?: number;
}[], </s> remove operations: [[actionSendBackward, ["A", "C", "D", "B"]]],
</s> add operations: [[actionSendBackward, ["A", "D", "B", "C"]]], </s> remove [actionSendBackward, ["B", "C", "D", "A"]],
</s> add [actionSendBackward, ["D", "A", "B", "C"]],
// noop
[actionSendBackward, ["D", "A", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [ </s> remove render(<App />);
</s> add assertZindex({
elements: [
{ id: "A" },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
{ id: "D", isDeleted: true },
{ id: "E" },
],
operations: [
[actionBringForward, ["A", "D", "E", "B", "C"]],
// noop
[actionBringForward, ["A", "D", "E", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [
// noop
[actionBringForward, ["A", "B", "C"]],
],
});
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> });
<mask> };
<mask>
<mask> describe("z-index manipulation", () => {
<mask> it("send back", () => {
<mask> render(<App />);
<mask>
<mask> assertZindex({
<mask> elements: [
<mask> { id: "A" },
</s> fix zindex to account for group boundaries (#2065) </s> add }); </s> remove render(<App />);
</s> add </s> add it("send back", () => { </s> remove render(<App />);
</s> add </s> remove render(<App />);
</s> add assertZindex({
elements: [
{ id: "A" },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
{ id: "D", isDeleted: true },
{ id: "E" },
],
operations: [
[actionBringForward, ["A", "D", "E", "B", "C"]],
// noop
[actionBringForward, ["A", "D", "E", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [
// noop
[actionBringForward, ["A", "B", "C"]],
],
}); </s> remove operations: [[actionSendBackward, ["B", "C", "D", "E", "A"]]],
</s> add
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep add keep keep keep keep keep
|
<mask>
<mask> describe("z-index manipulation", () => {
<mask> beforeEach(() => {
<mask> render(<App />);
<mask>
<mask> it("send back", () => {
<mask> assertZindex({
<mask> elements: [
<mask> { id: "A" },
</s> fix zindex to account for group boundaries (#2065) </s> remove it("send back", () => {
</s> add beforeEach(() => { </s> remove render(<App />);
</s> add </s> add it("send back", () => { </s> remove render(<App />);
</s> add </s> remove render(<App />);
</s> add assertZindex({
elements: [
{ id: "A" },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
{ id: "D", isDeleted: true },
{ id: "E" },
],
operations: [
[actionBringForward, ["A", "D", "E", "B", "C"]],
// noop
[actionBringForward, ["A", "D", "E", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [
// noop
[actionBringForward, ["A", "B", "C"]],
],
}); </s> remove operations: [[actionSendBackward, ["B", "C", "D", "E", "A"]]],
</s> add
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep add keep keep keep keep
|
<mask> });
<mask>
<mask> assertZindex({
<mask> elements: [
<mask> { id: "A" },
<mask> { id: "B", isDeleted: true },
</s> fix zindex to account for group boundaries (#2065) </s> remove render(<App />);
</s> add assertZindex({
elements: [
{ id: "A" },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
{ id: "D", isDeleted: true },
{ id: "E" },
],
operations: [
[actionBringForward, ["A", "D", "E", "B", "C"]],
// noop
[actionBringForward, ["A", "D", "E", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [
// noop
[actionBringForward, ["A", "B", "C"]],
],
}); </s> remove render(<App />);
</s> add </s> remove operations: [[actionSendBackward, ["A", "C", "D", "B"]]],
</s> add operations: [[actionSendBackward, ["A", "D", "B", "C"]]], </s> add { id: "0" }, </s> remove render(<App />);
</s> add </s> remove operations: [[actionSendBackward, ["B", "C", "D", "E", "A"]]],
</s> add
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> { id: "C", isDeleted: true },
<mask> { id: "D", isSelected: true },
<mask> ],
<mask> operations: [
<mask> [actionSendBackward, ["B", "C", "D", "A"]],
<mask> // noop
<mask> [actionSendBackward, ["B", "C", "D", "A"]],
<mask> ],
<mask> });
<mask>
</s> fix zindex to account for group boundaries (#2065) </s> remove [actionSendBackward, ["B", "C", "D", "A"]],
</s> add [actionSendBackward, ["A", "B", "C"]], </s> remove operations: [[actionSendBackward, ["B", "C", "D", "E", "A"]]],
</s> add </s> add { id: "F" },
],
operations: [
[actionSendBackward, ["D", "E", "A", "B", "C", "F"]],
// noop
[actionSendBackward, ["D", "E", "A", "B", "C", "F"]], </s> remove render(<App />);
</s> add assertZindex({
elements: [
{ id: "A" },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
{ id: "D", isDeleted: true },
{ id: "E" },
],
operations: [
[actionBringForward, ["A", "D", "E", "B", "C"]],
// noop
[actionBringForward, ["A", "D", "E", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [
// noop
[actionBringForward, ["A", "B", "C"]],
],
}); </s> remove operations: [[actionSendBackward, ["A", "C", "D", "B"]]],
</s> add operations: [[actionSendBackward, ["A", "D", "B", "C"]]], </s> remove operations: [[actionSendToBack, ["D", "E", "A", "B", "C", "F", "G"]]],
</s> add
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> ],
<mask> operations: [
<mask> [actionSendBackward, ["B", "C", "D", "A"]],
<mask> // noop
<mask> [actionSendBackward, ["B", "C", "D", "A"]],
<mask> ],
<mask> });
<mask>
<mask> assertZindex({
<mask> elements: [
</s> fix zindex to account for group boundaries (#2065) </s> remove [actionSendBackward, ["B", "C", "D", "A"]],
</s> add [actionSendBackward, ["D", "A", "B", "C"]],
// noop
[actionSendBackward, ["D", "A", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [ </s> add { id: "F" },
],
operations: [
[actionSendBackward, ["D", "E", "A", "B", "C", "F"]],
// noop
[actionSendBackward, ["D", "E", "A", "B", "C", "F"]], </s> remove operations: [[actionSendBackward, ["B", "C", "D", "E", "A"]]],
</s> add </s> remove render(<App />);
</s> add assertZindex({
elements: [
{ id: "A" },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
{ id: "D", isDeleted: true },
{ id: "E" },
],
operations: [
[actionBringForward, ["A", "D", "E", "B", "C"]],
// noop
[actionBringForward, ["A", "D", "E", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [
// noop
[actionBringForward, ["A", "B", "C"]],
],
}); </s> remove operations: [[actionSendBackward, ["A", "C", "D", "B"]]],
</s> add operations: [[actionSendBackward, ["A", "D", "B", "C"]]], </s> remove operations: [[actionSendToBack, ["D", "E", "A", "B", "C", "F", "G"]]],
</s> add
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> { id: "B" },
<mask> { id: "C", isDeleted: true },
<mask> { id: "D", isSelected: true },
<mask> ],
<mask> operations: [[actionSendBackward, ["A", "C", "D", "B"]]],
<mask> });
<mask>
<mask> assertZindex({
<mask> elements: [
<mask> { id: "A" },
</s> fix zindex to account for group boundaries (#2065) </s> remove operations: [[actionSendBackward, ["B", "C", "D", "E", "A"]]],
</s> add </s> remove render(<App />);
</s> add assertZindex({
elements: [
{ id: "A" },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
{ id: "D", isDeleted: true },
{ id: "E" },
],
operations: [
[actionBringForward, ["A", "D", "E", "B", "C"]],
// noop
[actionBringForward, ["A", "D", "E", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [
// noop
[actionBringForward, ["A", "B", "C"]],
],
}); </s> remove [actionSendBackward, ["B", "C", "D", "A"]],
</s> add [actionSendBackward, ["D", "A", "B", "C"]],
// noop
[actionSendBackward, ["D", "A", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [ </s> add { id: "F" },
],
operations: [
[actionSendBackward, ["D", "E", "A", "B", "C", "F"]],
// noop
[actionSendBackward, ["D", "E", "A", "B", "C", "F"]], </s> add { id: "0" }, </s> remove render(<App />);
</s> add
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep add keep keep keep keep keep keep
|
<mask> { id: "D", isSelected: true },
<mask> { id: "E", isSelected: true },
<mask> ],
<mask> });
<mask>
<mask> assertZindex({
<mask> elements: [
<mask> { id: "A" },
</s> fix zindex to account for group boundaries (#2065) </s> remove operations: [[actionSendBackward, ["B", "C", "D", "E", "A"]]],
</s> add </s> remove render(<App />);
</s> add assertZindex({
elements: [
{ id: "A" },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
{ id: "D", isDeleted: true },
{ id: "E" },
],
operations: [
[actionBringForward, ["A", "D", "E", "B", "C"]],
// noop
[actionBringForward, ["A", "D", "E", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [
// noop
[actionBringForward, ["A", "B", "C"]],
],
}); </s> remove operations: [[actionSendBackward, ["A", "C", "D", "B"]]],
</s> add operations: [[actionSendBackward, ["A", "D", "B", "C"]]], </s> remove [actionSendBackward, ["B", "C", "D", "A"]],
</s> add [actionSendBackward, ["D", "A", "B", "C"]],
// noop
[actionSendBackward, ["D", "A", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [ </s> remove operations: [[actionSendToBack, ["D", "E", "A", "B", "C", "F", "G"]]],
</s> add </s> add { id: "0" },
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> { id: "C", isDeleted: true },
<mask> { id: "D", isSelected: true },
<mask> { id: "E", isSelected: true },
<mask> ],
<mask> operations: [[actionSendBackward, ["B", "C", "D", "E", "A"]]],
<mask> });
<mask>
<mask> assertZindex({
<mask> elements: [
<mask> { id: "A" },
</s> fix zindex to account for group boundaries (#2065) </s> remove render(<App />);
</s> add assertZindex({
elements: [
{ id: "A" },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
{ id: "D", isDeleted: true },
{ id: "E" },
],
operations: [
[actionBringForward, ["A", "D", "E", "B", "C"]],
// noop
[actionBringForward, ["A", "D", "E", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [
// noop
[actionBringForward, ["A", "B", "C"]],
],
}); </s> remove operations: [[actionSendBackward, ["A", "C", "D", "B"]]],
</s> add operations: [[actionSendBackward, ["A", "D", "B", "C"]]], </s> add { id: "F" },
],
operations: [
[actionSendBackward, ["D", "E", "A", "B", "C", "F"]],
// noop
[actionSendBackward, ["D", "E", "A", "B", "C", "F"]], </s> remove [actionSendBackward, ["B", "C", "D", "A"]],
</s> add [actionSendBackward, ["D", "A", "B", "C"]],
// noop
[actionSendBackward, ["D", "A", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [ </s> remove operations: [[actionSendToBack, ["D", "E", "A", "B", "C", "F", "G"]]],
</s> add </s> add { id: "0" },
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> });
<mask> });
<mask>
<mask> it("bring forward", () => {
<mask> render(<App />);
<mask>
<mask> assertZindex({
<mask> elements: [
<mask> { id: "A", isSelected: true },
<mask> { id: "B", isDeleted: true },
</s> fix zindex to account for group boundaries (#2065) </s> remove render(<App />);
</s> add </s> remove render(<App />);
</s> add </s> add { id: "0" }, </s> remove [actionSendBackward, ["B", "C", "D", "A"]],
</s> add [actionSendBackward, ["D", "A", "B", "C"]],
// noop
[actionSendBackward, ["D", "A", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [ </s> add { id: "F" },
],
operations: [
[actionSendBackward, ["D", "E", "A", "B", "C", "F"]],
// noop
[actionSendBackward, ["D", "E", "A", "B", "C", "F"]], </s> add it("send back", () => {
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep keep replace replace keep keep keep keep keep
|
<mask> });
<mask> });
<mask>
<mask> it("bring to front", () => {
<mask> render(<App />);
<mask>
<mask> assertZindex({
<mask> elements: [
<mask> { id: "A", isSelected: true },
<mask> { id: "B", isDeleted: true },
<mask> { id: "C", isDeleted: true },
</s> fix zindex to account for group boundaries (#2065) </s> remove render(<App />);
</s> add assertZindex({
elements: [
{ id: "A" },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
{ id: "D", isDeleted: true },
{ id: "E" },
],
operations: [
[actionBringForward, ["A", "D", "E", "B", "C"]],
// noop
[actionBringForward, ["A", "D", "E", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [
// noop
[actionBringForward, ["A", "B", "C"]],
],
}); </s> add { id: "0" }, </s> remove render(<App />);
</s> add </s> remove [actionSendBackward, ["B", "C", "D", "A"]],
</s> add [actionSendBackward, ["D", "A", "B", "C"]],
// noop
[actionSendBackward, ["D", "A", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [ </s> remove operations: [[actionSendToBack, ["D", "E", "A", "B", "C", "F", "G"]]],
</s> add </s> remove operations: [[actionSendBackward, ["B", "C", "D", "E", "A"]]],
</s> add
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep add keep keep keep keep
|
<mask> assertZindex({
<mask> elements: [
<mask> { id: "A", isSelected: true },
<mask> { id: "B", isDeleted: true },
<mask> { id: "C", isDeleted: true },
<mask> { id: "D" },
</s> fix zindex to account for group boundaries (#2065) </s> remove render(<App />);
</s> add assertZindex({
elements: [
{ id: "A" },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
{ id: "D", isDeleted: true },
{ id: "E" },
],
operations: [
[actionBringForward, ["A", "D", "E", "B", "C"]],
// noop
[actionBringForward, ["A", "D", "E", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [
// noop
[actionBringForward, ["A", "B", "C"]],
],
}); </s> remove render(<App />);
</s> add </s> remove [actionSendBackward, ["B", "C", "D", "A"]],
</s> add [actionSendBackward, ["D", "A", "B", "C"]],
// noop
[actionSendBackward, ["D", "A", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [ </s> remove operations: [[actionSendBackward, ["B", "C", "D", "E", "A"]]],
</s> add </s> remove operations: [[actionSendToBack, ["D", "E", "A", "B", "C", "F", "G"]]],
</s> add </s> remove operations: [[actionSendBackward, ["A", "C", "D", "B"]]],
</s> add operations: [[actionSendBackward, ["A", "D", "B", "C"]]],
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep keep replace replace keep keep keep keep keep
|
<mask> });
<mask> });
<mask>
<mask> it("send to back", () => {
<mask> render(<App />);
<mask>
<mask> assertZindex({
<mask> elements: [
<mask> { id: "A" },
<mask> { id: "B", isDeleted: true },
<mask> { id: "C" },
</s> fix zindex to account for group boundaries (#2065) </s> add it("send back", () => { </s> remove render(<App />);
</s> add </s> add }); </s> remove it("send back", () => {
</s> add beforeEach(() => { </s> remove render(<App />);
</s> add assertZindex({
elements: [
{ id: "A" },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
{ id: "D", isDeleted: true },
{ id: "E" },
],
operations: [
[actionBringForward, ["A", "D", "E", "B", "C"]],
// noop
[actionBringForward, ["A", "D", "E", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [
// noop
[actionBringForward, ["A", "B", "C"]],
],
}); </s> remove operations: [[actionSendBackward, ["A", "C", "D", "B"]]],
</s> add operations: [[actionSendBackward, ["A", "D", "B", "C"]]],
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
keep keep keep keep replace keep keep keep
|
<mask> { id: "E", isSelected: true },
<mask> { id: "F", isDeleted: true },
<mask> { id: "G" },
<mask> ],
<mask> operations: [[actionSendToBack, ["D", "E", "A", "B", "C", "F", "G"]]],
<mask> });
<mask> });
<mask> });
</s> fix zindex to account for group boundaries (#2065) </s> add { id: "F" },
],
operations: [
[actionSendBackward, ["D", "E", "A", "B", "C", "F"]],
// noop
[actionSendBackward, ["D", "E", "A", "B", "C", "F"]], </s> remove render(<App />);
</s> add assertZindex({
elements: [
{ id: "A" },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
{ id: "D", isDeleted: true },
{ id: "E" },
],
operations: [
[actionBringForward, ["A", "D", "E", "B", "C"]],
// noop
[actionBringForward, ["A", "D", "E", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [
// noop
[actionBringForward, ["A", "B", "C"]],
],
}); </s> remove [actionSendBackward, ["B", "C", "D", "A"]],
</s> add [actionSendBackward, ["D", "A", "B", "C"]],
// noop
[actionSendBackward, ["D", "A", "B", "C"]],
],
});
assertZindex({
elements: [
{ id: "A", isSelected: true },
{ id: "B", isSelected: true },
{ id: "C", isSelected: true },
],
operations: [ </s> remove operations: [[actionSendBackward, ["B", "C", "D", "E", "A"]]],
</s> add </s> add { id: "0" }, </s> remove render(<App />);
</s> add
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/tests/zindex.test.tsx
|
replace replace replace replace replace keep replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
|
<mask> const swap = <T>(elements: T[], indexA: number, indexB: number) => {
<mask> const element = elements[indexA];
<mask> elements[indexA] = elements[indexB];
<mask> elements[indexB] = element;
<mask> };
<mask>
<mask> export const moveOneLeft = <T>(elements: T[], indicesToMove: number[]) => {
<mask> indicesToMove.sort((a: number, b: number) => a - b);
<mask> let isSorted = true;
<mask> // We go from left to right to avoid overriding the wrong elements
<mask> indicesToMove.forEach((index, i) => {
<mask> // We don't want to bubble the first elements that are sorted as they are
<mask> // already in their correct position
<mask> isSorted = isSorted && index === i;
<mask> if (isSorted) {
<mask> return;
<mask> }
<mask> swap(elements, index - 1, index);
<mask> });
<mask>
<mask> return elements;
</s> fix zindex to account for group boundaries (#2065) </s> remove export const moveOneRight = <T>(elements: T[], indicesToMove: number[]) => {
const reversedIndicesToMove = indicesToMove.sort(
(a: number, b: number) => b - a,
);
let isSorted = true;
// We go from right to left to avoid overriding the wrong elements
reversedIndicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === elements.length - i - 1;
if (isSorted) {
return;
</s> add /**
* Returns next candidate index that's available to be moved to. Currently that
* is a non-deleted element, and not inside a group (unless we're editing it).
*/
const getTargetIndex = (
appState: AppState,
elements: ExcalidrawElement[],
boundaryIndex: number,
direction: "left" | "right",
) => {
const sourceElement = elements[boundaryIndex];
const indexFilter = (element: ExcalidrawElement) => {
if (element.isDeleted) {
return false; </s> remove swap(elements, index - 1, index);
});
</s> add }
return selectedIndices;
}; </s> remove // Let's go through an example
// | |
// [a, b, c, d, e, f, g]
// -->
// [a, b, d, e, g, c, f]
//
// We are going to override all the elements we want to move, so we keep them in an array
// that we will restore at the end.
// [c, f]
//
// From now on, we'll never read those values from the array anymore
// |0 |1
// [a, b, _, d, e, _, g]
//
// The idea is that we want to shift all the elements between the marker 0 and 1
// by one slot to the left.
//
// |0 |1
// [a, b, _, d, e, _, g]
// <- <-
//
// which gives us
//
// |0 |1
// [a, b, d, e, _, _, g]
//
// Now, we need to move all the elements from marker 1 to the end by two (not one)
// slots to the left, which gives us
//
// |0 |1
// [a, b, d, e, _, _, g]
// ^------
//
// which gives us
//
// |0 |1
// [a, b, d, e, g, _, _]
//
// At this point, we can fill back the rightmost elements with the array we saved at
// the beginning
//
// |0 |1
// [a, b, d, e, g, c, f]
//
// And we are done!
export const moveAllRight = <T>(elements: T[], indicesToMove: number[]) => {
const reversedIndicesToMove = indicesToMove.sort(
(a: number, b: number) => b - a,
);
// Copy the elements to move
const rightMostElements = reversedIndicesToMove.map(
(index) => elements[index],
);
indicesToMove = reversedIndicesToMove
// We go from left to right to avoid overriding elements.
.reverse()
// We last element index for the final marker
.concat([elements.length]);
indicesToMove.forEach((index, i) => {
// We skip the first one as it is not paired with anything else
if (i === 0) {
return;
</s> add const shiftElementsToEnd = (
elements: readonly ExcalidrawElement[],
appState: AppState,
direction: "left" | "right",
) => {
const indicesToMove = getIndicesToMove(elements, appState);
const targetElements: ExcalidrawElement[] = [];
const displacedElements: ExcalidrawElement[] = [];
let leadingIndex, trailingIndex;
if (direction === "left") {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
leadingIndex = elements.indexOf(groupElements[0]);
} else {
leadingIndex = 0; </s> remove // Let's go through an example
// | |
// [a, b, c, d, e, f, g]
// -->
// [c, f, a, b, d, e, g]
//
// We are going to override all the elements we want to move, so we keep them in an array
// that we will restore at the end.
// [c, f]
//
// From now on, we'll never read those values from the array anymore
// |1 |0
// [a, b, _, d, e, _, g]
//
// The idea is that we want to shift all the elements between the marker 0 and 1
// by one slot to the right.
//
// |1 |0
// [a, b, _, d, e, _, g]
// -> ->
//
// which gives us
//
// |1 |0
// [a, b, _, _, d, e, g]
//
// Now, we need to move all the elements from marker 1 to the beginning by two (not one)
// slots to the right, which gives us
//
// |1 |0
// [a, b, _, _, d, e, g]
// ---|--^ ^
// ------|
//
// which gives us
//
// |1 |0
// [_, _, a, b, d, e, g]
//
// At this point, we can fill back the leftmost elements with the array we saved at
// the beginning
//
// |1 |0
// [c, f, a, b, d, e, g]
//
// And we are done!
export const moveAllLeft = <T>(elements: T[], indicesToMove: number[]) => {
indicesToMove.sort((a: number, b: number) => a - b);
// Copy the elements to move
const leftMostElements = indicesToMove.map((index) => elements[index]);
const reversedIndicesToMove = indicesToMove
// We go from right to left to avoid overriding elements.
.reverse()
// We add 0 for the final marker
.concat([0]);
reversedIndicesToMove.forEach((index, i) => {
// We skip the first one as it is not paired with anything else
if (i === 0) {
</s> add const shiftElements = (
appState: AppState,
elements: ExcalidrawElement[],
direction: "left" | "right",
) => {
const indicesToMove = getIndicesToMove(elements, appState);
let groupedIndices = toContiguousGroups(indicesToMove);
if (direction === "right") {
groupedIndices = groupedIndices.reverse();
}
groupedIndices.forEach((indices, i) => {
const leadingIndex = indices[0];
const trailingIndex = indices[indices.length - 1];
const boundaryIndex = direction === "left" ? leadingIndex : trailingIndex;
const targetIndex = getTargetIndex(
appState,
elements,
boundaryIndex,
direction,
);
if (targetIndex === -1 || boundaryIndex === targetIndex) { </s> remove return elements;
</s> add const toContiguousGroups = (array: number[]) => {
let cursor = 0;
return array.reduce((acc, value, index) => {
if (index > 0 && array[index - 1] !== value - 1) {
cursor = ++cursor;
}
(acc[cursor] || (acc[cursor] = [])).push(value);
return acc;
}, [] as number[][]);
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/zindex.ts
|
keep keep keep replace replace keep replace keep keep keep
|
<mask> if (isSorted) {
<mask> return;
<mask> }
<mask> swap(elements, index - 1, index);
<mask> });
<mask>
<mask> return elements;
<mask> };
<mask>
<mask> export const moveOneRight = <T>(elements: T[], indicesToMove: number[]) => {
</s> fix zindex to account for group boundaries (#2065) </s> remove export const moveOneRight = <T>(elements: T[], indicesToMove: number[]) => {
const reversedIndicesToMove = indicesToMove.sort(
(a: number, b: number) => b - a,
);
let isSorted = true;
// We go from right to left to avoid overriding the wrong elements
reversedIndicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === elements.length - i - 1;
if (isSorted) {
return;
</s> add /**
* Returns next candidate index that's available to be moved to. Currently that
* is a non-deleted element, and not inside a group (unless we're editing it).
*/
const getTargetIndex = (
appState: AppState,
elements: ExcalidrawElement[],
boundaryIndex: number,
direction: "left" | "right",
) => {
const sourceElement = elements[boundaryIndex];
const indexFilter = (element: ExcalidrawElement) => {
if (element.isDeleted) {
return false; </s> remove export const moveOneLeft = <T>(elements: T[], indicesToMove: number[]) => {
indicesToMove.sort((a: number, b: number) => a - b);
let isSorted = true;
// We go from left to right to avoid overriding the wrong elements
indicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === i;
if (isSorted) {
return;
</s> add /**
* Returns indices of elements to move based on selected elements.
* Includes contiguous deleted elements that are between two selected elements,
* e.g.: [0 (selected), 1 (deleted), 2 (deleted), 3 (selected)]
*/
const getIndicesToMove = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
let selectedIndices: number[] = [];
let deletedIndices: number[] = [];
let includeDeletedIndex = null;
let i = -1;
while (++i < elements.length) {
if (appState.selectedElementIds[elements[i].id]) {
if (deletedIndices.length) {
selectedIndices = selectedIndices.concat(deletedIndices);
deletedIndices = [];
}
selectedIndices.push(i);
includeDeletedIndex = i + 1;
} else if (elements[i].isDeleted && includeDeletedIndex === i) {
includeDeletedIndex = i + 1;
deletedIndices.push(i);
} else {
deletedIndices = []; </s> remove const swap = <T>(elements: T[], indexA: number, indexB: number) => {
const element = elements[indexA];
elements[indexA] = elements[indexB];
elements[indexB] = element;
};
</s> add import { AppState } from "./types";
import { ExcalidrawElement } from "./element/types";
import { getElementsInGroup } from "./groups";
import { findLastIndex, findIndex } from "./utils"; </s> remove return elements;
</s> add for (let index = leadingIndex; index < trailingIndex + 1; index++) {
if (indicesToMove.includes(index)) {
targetElements.push(elements[index]);
} else {
displacedElements.push(elements[index]);
}
}
const leadingElements = elements.slice(0, leadingIndex);
const trailingElements = elements.slice(trailingIndex + 1);
return direction === "left"
? [
...leadingElements,
...targetElements,
...displacedElements,
...trailingElements,
]
: [
...leadingElements,
...displacedElements,
...targetElements,
...trailingElements,
];
};
// public API
// -----------------------------------------------------------------------------
export const moveOneLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "left");
};
export const moveOneRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "right");
};
export const moveAllLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "left");
};
export const moveAllRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "right"); </s> remove // We go from the next marker to the left (i - 1) to the current one (index)
for (let pos = indicesToMove[i - 1] + 1; pos < index; ++pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos - i] = elements[pos];
</s> add trailingIndex = indicesToMove[indicesToMove.length - 1];
} else {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
trailingIndex = elements.indexOf(groupElements[groupElements.length - 1]);
} else {
trailingIndex = elements.length - 1;
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/zindex.ts
|
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
|
<mask>
<mask> return elements;
<mask> };
<mask>
<mask> export const moveOneRight = <T>(elements: T[], indicesToMove: number[]) => {
<mask> const reversedIndicesToMove = indicesToMove.sort(
<mask> (a: number, b: number) => b - a,
<mask> );
<mask> let isSorted = true;
<mask>
<mask> // We go from right to left to avoid overriding the wrong elements
<mask> reversedIndicesToMove.forEach((index, i) => {
<mask> // We don't want to bubble the first elements that are sorted as they are
<mask> // already in their correct position
<mask> isSorted = isSorted && index === elements.length - i - 1;
<mask> if (isSorted) {
<mask> return;
<mask> }
<mask> swap(elements, index + 1, index);
<mask> });
<mask> return elements;
<mask> };
</s> fix zindex to account for group boundaries (#2065) </s> remove export const moveOneLeft = <T>(elements: T[], indicesToMove: number[]) => {
indicesToMove.sort((a: number, b: number) => a - b);
let isSorted = true;
// We go from left to right to avoid overriding the wrong elements
indicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === i;
if (isSorted) {
return;
</s> add /**
* Returns indices of elements to move based on selected elements.
* Includes contiguous deleted elements that are between two selected elements,
* e.g.: [0 (selected), 1 (deleted), 2 (deleted), 3 (selected)]
*/
const getIndicesToMove = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
let selectedIndices: number[] = [];
let deletedIndices: number[] = [];
let includeDeletedIndex = null;
let i = -1;
while (++i < elements.length) {
if (appState.selectedElementIds[elements[i].id]) {
if (deletedIndices.length) {
selectedIndices = selectedIndices.concat(deletedIndices);
deletedIndices = [];
}
selectedIndices.push(i);
includeDeletedIndex = i + 1;
} else if (elements[i].isDeleted && includeDeletedIndex === i) {
includeDeletedIndex = i + 1;
deletedIndices.push(i);
} else {
deletedIndices = []; </s> remove swap(elements, index - 1, index);
});
</s> add }
return selectedIndices;
}; </s> remove const swap = <T>(elements: T[], indexA: number, indexB: number) => {
const element = elements[indexA];
elements[indexA] = elements[indexB];
elements[indexB] = element;
};
</s> add import { AppState } from "./types";
import { ExcalidrawElement } from "./element/types";
import { getElementsInGroup } from "./groups";
import { findLastIndex, findIndex } from "./utils"; </s> remove return elements;
</s> add const toContiguousGroups = (array: number[]) => {
let cursor = 0;
return array.reduce((acc, value, index) => {
if (index > 0 && array[index - 1] !== value - 1) {
cursor = ++cursor;
}
(acc[cursor] || (acc[cursor] = [])).push(value);
return acc;
}, [] as number[][]); </s> remove // Let's go through an example
// | |
// [a, b, c, d, e, f, g]
// -->
// [a, b, d, e, g, c, f]
//
// We are going to override all the elements we want to move, so we keep them in an array
// that we will restore at the end.
// [c, f]
//
// From now on, we'll never read those values from the array anymore
// |0 |1
// [a, b, _, d, e, _, g]
//
// The idea is that we want to shift all the elements between the marker 0 and 1
// by one slot to the left.
//
// |0 |1
// [a, b, _, d, e, _, g]
// <- <-
//
// which gives us
//
// |0 |1
// [a, b, d, e, _, _, g]
//
// Now, we need to move all the elements from marker 1 to the end by two (not one)
// slots to the left, which gives us
//
// |0 |1
// [a, b, d, e, _, _, g]
// ^------
//
// which gives us
//
// |0 |1
// [a, b, d, e, g, _, _]
//
// At this point, we can fill back the rightmost elements with the array we saved at
// the beginning
//
// |0 |1
// [a, b, d, e, g, c, f]
//
// And we are done!
export const moveAllRight = <T>(elements: T[], indicesToMove: number[]) => {
const reversedIndicesToMove = indicesToMove.sort(
(a: number, b: number) => b - a,
);
// Copy the elements to move
const rightMostElements = reversedIndicesToMove.map(
(index) => elements[index],
);
indicesToMove = reversedIndicesToMove
// We go from left to right to avoid overriding elements.
.reverse()
// We last element index for the final marker
.concat([elements.length]);
indicesToMove.forEach((index, i) => {
// We skip the first one as it is not paired with anything else
if (i === 0) {
return;
</s> add const shiftElementsToEnd = (
elements: readonly ExcalidrawElement[],
appState: AppState,
direction: "left" | "right",
) => {
const indicesToMove = getIndicesToMove(elements, appState);
const targetElements: ExcalidrawElement[] = [];
const displacedElements: ExcalidrawElement[] = [];
let leadingIndex, trailingIndex;
if (direction === "left") {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
leadingIndex = elements.indexOf(groupElements[0]);
} else {
leadingIndex = 0; </s> remove // We go from the next marker to the left (i - 1) to the current one (index)
for (let pos = indicesToMove[i - 1] + 1; pos < index; ++pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos - i] = elements[pos];
</s> add trailingIndex = indicesToMove[indicesToMove.length - 1];
} else {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
trailingIndex = elements.indexOf(groupElements[groupElements.length - 1]);
} else {
trailingIndex = elements.length - 1;
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/zindex.ts
|
keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep replace replace replace replace replace replace keep keep
|
<mask>
<mask> // Let's go through an example
<mask> // | |
<mask> // [a, b, c, d, e, f, g]
<mask> // -->
<mask> // [c, f, a, b, d, e, g]
<mask> //
<mask> // We are going to override all the elements we want to move, so we keep them in an array
<mask> // that we will restore at the end.
<mask> // [c, f]
<mask> //
<mask> // From now on, we'll never read those values from the array anymore
<mask> // |1 |0
<mask> // [a, b, _, d, e, _, g]
<mask> //
<mask> // The idea is that we want to shift all the elements between the marker 0 and 1
<mask> // by one slot to the right.
<mask> //
<mask> // |1 |0
<mask> // [a, b, _, d, e, _, g]
<mask> // -> ->
<mask> //
<mask> // which gives us
<mask> //
<mask> // |1 |0
<mask> // [a, b, _, _, d, e, g]
<mask> //
<mask> // Now, we need to move all the elements from marker 1 to the beginning by two (not one)
<mask> // slots to the right, which gives us
<mask> //
<mask> // |1 |0
<mask> // [a, b, _, _, d, e, g]
<mask> // ---|--^ ^
<mask> // ------|
<mask> //
<mask> // which gives us
<mask> //
<mask> // |1 |0
<mask> // [_, _, a, b, d, e, g]
<mask> //
<mask> // At this point, we can fill back the leftmost elements with the array we saved at
<mask> // the beginning
<mask> //
<mask> // |1 |0
<mask> // [c, f, a, b, d, e, g]
<mask> //
<mask> // And we are done!
<mask> export const moveAllLeft = <T>(elements: T[], indicesToMove: number[]) => {
<mask> indicesToMove.sort((a: number, b: number) => a - b);
<mask>
<mask> // Copy the elements to move
<mask> const leftMostElements = indicesToMove.map((index) => elements[index]);
<mask>
<mask> const reversedIndicesToMove = indicesToMove
<mask> // We go from right to left to avoid overriding elements.
<mask> .reverse()
<mask> // We add 0 for the final marker
<mask> .concat([0]);
<mask>
<mask> reversedIndicesToMove.forEach((index, i) => {
<mask> // We skip the first one as it is not paired with anything else
<mask> if (i === 0) {
<mask> return;
<mask> }
<mask>
<mask> // We go from the next marker to the right (i - 1) to the current one (index)
<mask> for (let pos = reversedIndicesToMove[i - 1] - 1; pos >= index; --pos) {
<mask> // We move by 1 the first time, 2 the second... So we can use the index i in the array
<mask> elements[pos + i] = elements[pos];
<mask> }
<mask> });
<mask>
<mask> // The final step
</s> fix zindex to account for group boundaries (#2065) </s> remove // Let's go through an example
// | |
// [a, b, c, d, e, f, g]
// -->
// [a, b, d, e, g, c, f]
//
// We are going to override all the elements we want to move, so we keep them in an array
// that we will restore at the end.
// [c, f]
//
// From now on, we'll never read those values from the array anymore
// |0 |1
// [a, b, _, d, e, _, g]
//
// The idea is that we want to shift all the elements between the marker 0 and 1
// by one slot to the left.
//
// |0 |1
// [a, b, _, d, e, _, g]
// <- <-
//
// which gives us
//
// |0 |1
// [a, b, d, e, _, _, g]
//
// Now, we need to move all the elements from marker 1 to the end by two (not one)
// slots to the left, which gives us
//
// |0 |1
// [a, b, d, e, _, _, g]
// ^------
//
// which gives us
//
// |0 |1
// [a, b, d, e, g, _, _]
//
// At this point, we can fill back the rightmost elements with the array we saved at
// the beginning
//
// |0 |1
// [a, b, d, e, g, c, f]
//
// And we are done!
export const moveAllRight = <T>(elements: T[], indicesToMove: number[]) => {
const reversedIndicesToMove = indicesToMove.sort(
(a: number, b: number) => b - a,
);
// Copy the elements to move
const rightMostElements = reversedIndicesToMove.map(
(index) => elements[index],
);
indicesToMove = reversedIndicesToMove
// We go from left to right to avoid overriding elements.
.reverse()
// We last element index for the final marker
.concat([elements.length]);
indicesToMove.forEach((index, i) => {
// We skip the first one as it is not paired with anything else
if (i === 0) {
return;
</s> add const shiftElementsToEnd = (
elements: readonly ExcalidrawElement[],
appState: AppState,
direction: "left" | "right",
) => {
const indicesToMove = getIndicesToMove(elements, appState);
const targetElements: ExcalidrawElement[] = [];
const displacedElements: ExcalidrawElement[] = [];
let leadingIndex, trailingIndex;
if (direction === "left") {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
leadingIndex = elements.indexOf(groupElements[0]);
} else {
leadingIndex = 0; </s> remove // We go from the next marker to the left (i - 1) to the current one (index)
for (let pos = indicesToMove[i - 1] + 1; pos < index; ++pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos - i] = elements[pos];
</s> add trailingIndex = indicesToMove[indicesToMove.length - 1];
} else {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
trailingIndex = elements.indexOf(groupElements[groupElements.length - 1]);
} else {
trailingIndex = elements.length - 1; </s> remove });
</s> add </s> remove export const moveOneRight = <T>(elements: T[], indicesToMove: number[]) => {
const reversedIndicesToMove = indicesToMove.sort(
(a: number, b: number) => b - a,
);
let isSorted = true;
// We go from right to left to avoid overriding the wrong elements
reversedIndicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === elements.length - i - 1;
if (isSorted) {
return;
</s> add /**
* Returns next candidate index that's available to be moved to. Currently that
* is a non-deleted element, and not inside a group (unless we're editing it).
*/
const getTargetIndex = (
appState: AppState,
elements: ExcalidrawElement[],
boundaryIndex: number,
direction: "left" | "right",
) => {
const sourceElement = elements[boundaryIndex];
const indexFilter = (element: ExcalidrawElement) => {
if (element.isDeleted) {
return false; </s> remove export const moveOneLeft = <T>(elements: T[], indicesToMove: number[]) => {
indicesToMove.sort((a: number, b: number) => a - b);
let isSorted = true;
// We go from left to right to avoid overriding the wrong elements
indicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === i;
if (isSorted) {
return;
</s> add /**
* Returns indices of elements to move based on selected elements.
* Includes contiguous deleted elements that are between two selected elements,
* e.g.: [0 (selected), 1 (deleted), 2 (deleted), 3 (selected)]
*/
const getIndicesToMove = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
let selectedIndices: number[] = [];
let deletedIndices: number[] = [];
let includeDeletedIndex = null;
let i = -1;
while (++i < elements.length) {
if (appState.selectedElementIds[elements[i].id]) {
if (deletedIndices.length) {
selectedIndices = selectedIndices.concat(deletedIndices);
deletedIndices = [];
}
selectedIndices.push(i);
includeDeletedIndex = i + 1;
} else if (elements[i].isDeleted && includeDeletedIndex === i) {
includeDeletedIndex = i + 1;
deletedIndices.push(i);
} else {
deletedIndices = [];
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/zindex.ts
|
keep keep keep keep replace replace replace keep keep keep keep keep
|
<mask> elements[pos + i] = elements[pos];
<mask> }
<mask> });
<mask>
<mask> // The final step
<mask> leftMostElements.forEach((element, i) => {
<mask> elements[i] = element;
<mask> });
<mask>
<mask> return elements;
<mask> };
<mask>
</s> fix zindex to account for group boundaries (#2065) </s> remove // The final step
rightMostElements.forEach((element, i) => {
elements[elements.length - i - 1] = element;
});
</s> add leadingIndex = indicesToMove[0];
} </s> remove });
</s> add </s> remove // We go from the next marker to the right (i - 1) to the current one (index)
for (let pos = reversedIndicesToMove[i - 1] - 1; pos >= index; --pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos + i] = elements[pos];
}
});
</s> add const leadingElements =
direction === "left"
? elements.slice(0, targetIndex)
: elements.slice(0, leadingIndex);
const targetElements = elements.slice(leadingIndex, trailingIndex + 1);
const displacedElements =
direction === "left"
? elements.slice(targetIndex, leadingIndex)
: elements.slice(trailingIndex + 1, targetIndex + 1);
const trailingElements =
direction === "left"
? elements.slice(trailingIndex + 1)
: elements.slice(targetIndex + 1); </s> remove // We go from the next marker to the left (i - 1) to the current one (index)
for (let pos = indicesToMove[i - 1] + 1; pos < index; ++pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos - i] = elements[pos];
</s> add trailingIndex = indicesToMove[indicesToMove.length - 1];
} else {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
trailingIndex = elements.indexOf(groupElements[groupElements.length - 1]);
} else {
trailingIndex = elements.length - 1; </s> remove return elements;
</s> add for (let index = leadingIndex; index < trailingIndex + 1; index++) {
if (indicesToMove.includes(index)) {
targetElements.push(elements[index]);
} else {
displacedElements.push(elements[index]);
}
}
const leadingElements = elements.slice(0, leadingIndex);
const trailingElements = elements.slice(trailingIndex + 1);
return direction === "left"
? [
...leadingElements,
...targetElements,
...displacedElements,
...trailingElements,
]
: [
...leadingElements,
...displacedElements,
...targetElements,
...trailingElements,
];
};
// public API
// -----------------------------------------------------------------------------
export const moveOneLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "left");
};
export const moveOneRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElements(appState, elements.slice(), "right");
};
export const moveAllLeft = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "left");
};
export const moveAllRight = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return shiftElementsToEnd(elements, appState, "right"); </s> remove export const moveOneLeft = <T>(elements: T[], indicesToMove: number[]) => {
indicesToMove.sort((a: number, b: number) => a - b);
let isSorted = true;
// We go from left to right to avoid overriding the wrong elements
indicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === i;
if (isSorted) {
return;
</s> add /**
* Returns indices of elements to move based on selected elements.
* Includes contiguous deleted elements that are between two selected elements,
* e.g.: [0 (selected), 1 (deleted), 2 (deleted), 3 (selected)]
*/
const getIndicesToMove = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
let selectedIndices: number[] = [];
let deletedIndices: number[] = [];
let includeDeletedIndex = null;
let i = -1;
while (++i < elements.length) {
if (appState.selectedElementIds[elements[i].id]) {
if (deletedIndices.length) {
selectedIndices = selectedIndices.concat(deletedIndices);
deletedIndices = [];
}
selectedIndices.push(i);
includeDeletedIndex = i + 1;
} else if (elements[i].isDeleted && includeDeletedIndex === i) {
includeDeletedIndex = i + 1;
deletedIndices.push(i);
} else {
deletedIndices = [];
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/zindex.ts
|
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep replace replace replace replace
|
<mask>
<mask> return elements;
<mask> };
<mask>
<mask> // Let's go through an example
<mask> // | |
<mask> // [a, b, c, d, e, f, g]
<mask> // -->
<mask> // [a, b, d, e, g, c, f]
<mask> //
<mask> // We are going to override all the elements we want to move, so we keep them in an array
<mask> // that we will restore at the end.
<mask> // [c, f]
<mask> //
<mask> // From now on, we'll never read those values from the array anymore
<mask> // |0 |1
<mask> // [a, b, _, d, e, _, g]
<mask> //
<mask> // The idea is that we want to shift all the elements between the marker 0 and 1
<mask> // by one slot to the left.
<mask> //
<mask> // |0 |1
<mask> // [a, b, _, d, e, _, g]
<mask> // <- <-
<mask> //
<mask> // which gives us
<mask> //
<mask> // |0 |1
<mask> // [a, b, d, e, _, _, g]
<mask> //
<mask> // Now, we need to move all the elements from marker 1 to the end by two (not one)
<mask> // slots to the left, which gives us
<mask> //
<mask> // |0 |1
<mask> // [a, b, d, e, _, _, g]
<mask> // ^------
<mask> //
<mask> // which gives us
<mask> //
<mask> // |0 |1
<mask> // [a, b, d, e, g, _, _]
<mask> //
<mask> // At this point, we can fill back the rightmost elements with the array we saved at
<mask> // the beginning
<mask> //
<mask> // |0 |1
<mask> // [a, b, d, e, g, c, f]
<mask> //
<mask> // And we are done!
<mask> export const moveAllRight = <T>(elements: T[], indicesToMove: number[]) => {
<mask> const reversedIndicesToMove = indicesToMove.sort(
<mask> (a: number, b: number) => b - a,
<mask> );
<mask>
<mask> // Copy the elements to move
<mask> const rightMostElements = reversedIndicesToMove.map(
<mask> (index) => elements[index],
<mask> );
<mask>
<mask> indicesToMove = reversedIndicesToMove
<mask> // We go from left to right to avoid overriding elements.
<mask> .reverse()
<mask> // We last element index for the final marker
<mask> .concat([elements.length]);
<mask>
<mask> indicesToMove.forEach((index, i) => {
<mask> // We skip the first one as it is not paired with anything else
<mask> if (i === 0) {
<mask> return;
<mask> }
<mask>
<mask> // We go from the next marker to the left (i - 1) to the current one (index)
<mask> for (let pos = indicesToMove[i - 1] + 1; pos < index; ++pos) {
<mask> // We move by 1 the first time, 2 the second... So we can use the index i in the array
<mask> elements[pos - i] = elements[pos];
</s> fix zindex to account for group boundaries (#2065) </s> remove // Let's go through an example
// | |
// [a, b, c, d, e, f, g]
// -->
// [c, f, a, b, d, e, g]
//
// We are going to override all the elements we want to move, so we keep them in an array
// that we will restore at the end.
// [c, f]
//
// From now on, we'll never read those values from the array anymore
// |1 |0
// [a, b, _, d, e, _, g]
//
// The idea is that we want to shift all the elements between the marker 0 and 1
// by one slot to the right.
//
// |1 |0
// [a, b, _, d, e, _, g]
// -> ->
//
// which gives us
//
// |1 |0
// [a, b, _, _, d, e, g]
//
// Now, we need to move all the elements from marker 1 to the beginning by two (not one)
// slots to the right, which gives us
//
// |1 |0
// [a, b, _, _, d, e, g]
// ---|--^ ^
// ------|
//
// which gives us
//
// |1 |0
// [_, _, a, b, d, e, g]
//
// At this point, we can fill back the leftmost elements with the array we saved at
// the beginning
//
// |1 |0
// [c, f, a, b, d, e, g]
//
// And we are done!
export const moveAllLeft = <T>(elements: T[], indicesToMove: number[]) => {
indicesToMove.sort((a: number, b: number) => a - b);
// Copy the elements to move
const leftMostElements = indicesToMove.map((index) => elements[index]);
const reversedIndicesToMove = indicesToMove
// We go from right to left to avoid overriding elements.
.reverse()
// We add 0 for the final marker
.concat([0]);
reversedIndicesToMove.forEach((index, i) => {
// We skip the first one as it is not paired with anything else
if (i === 0) {
</s> add const shiftElements = (
appState: AppState,
elements: ExcalidrawElement[],
direction: "left" | "right",
) => {
const indicesToMove = getIndicesToMove(elements, appState);
let groupedIndices = toContiguousGroups(indicesToMove);
if (direction === "right") {
groupedIndices = groupedIndices.reverse();
}
groupedIndices.forEach((indices, i) => {
const leadingIndex = indices[0];
const trailingIndex = indices[indices.length - 1];
const boundaryIndex = direction === "left" ? leadingIndex : trailingIndex;
const targetIndex = getTargetIndex(
appState,
elements,
boundaryIndex,
direction,
);
if (targetIndex === -1 || boundaryIndex === targetIndex) { </s> remove // We go from the next marker to the right (i - 1) to the current one (index)
for (let pos = reversedIndicesToMove[i - 1] - 1; pos >= index; --pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos + i] = elements[pos];
}
});
</s> add const leadingElements =
direction === "left"
? elements.slice(0, targetIndex)
: elements.slice(0, leadingIndex);
const targetElements = elements.slice(leadingIndex, trailingIndex + 1);
const displacedElements =
direction === "left"
? elements.slice(targetIndex, leadingIndex)
: elements.slice(trailingIndex + 1, targetIndex + 1);
const trailingElements =
direction === "left"
? elements.slice(trailingIndex + 1)
: elements.slice(targetIndex + 1); </s> remove });
</s> add </s> remove export const moveOneRight = <T>(elements: T[], indicesToMove: number[]) => {
const reversedIndicesToMove = indicesToMove.sort(
(a: number, b: number) => b - a,
);
let isSorted = true;
// We go from right to left to avoid overriding the wrong elements
reversedIndicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === elements.length - i - 1;
if (isSorted) {
return;
</s> add /**
* Returns next candidate index that's available to be moved to. Currently that
* is a non-deleted element, and not inside a group (unless we're editing it).
*/
const getTargetIndex = (
appState: AppState,
elements: ExcalidrawElement[],
boundaryIndex: number,
direction: "left" | "right",
) => {
const sourceElement = elements[boundaryIndex];
const indexFilter = (element: ExcalidrawElement) => {
if (element.isDeleted) {
return false; </s> remove export const moveOneLeft = <T>(elements: T[], indicesToMove: number[]) => {
indicesToMove.sort((a: number, b: number) => a - b);
let isSorted = true;
// We go from left to right to avoid overriding the wrong elements
indicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === i;
if (isSorted) {
return;
</s> add /**
* Returns indices of elements to move based on selected elements.
* Includes contiguous deleted elements that are between two selected elements,
* e.g.: [0 (selected), 1 (deleted), 2 (deleted), 3 (selected)]
*/
const getIndicesToMove = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
let selectedIndices: number[] = [];
let deletedIndices: number[] = [];
let includeDeletedIndex = null;
let i = -1;
while (++i < elements.length) {
if (appState.selectedElementIds[elements[i].id]) {
if (deletedIndices.length) {
selectedIndices = selectedIndices.concat(deletedIndices);
deletedIndices = [];
}
selectedIndices.push(i);
includeDeletedIndex = i + 1;
} else if (elements[i].isDeleted && includeDeletedIndex === i) {
includeDeletedIndex = i + 1;
deletedIndices.push(i);
} else {
deletedIndices = [];
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/zindex.ts
|
keep keep keep keep replace keep replace replace replace replace
|
<mask> for (let pos = indicesToMove[i - 1] + 1; pos < index; ++pos) {
<mask> // We move by 1 the first time, 2 the second... So we can use the index i in the array
<mask> elements[pos - i] = elements[pos];
<mask> }
<mask> });
<mask>
<mask> // The final step
<mask> rightMostElements.forEach((element, i) => {
<mask> elements[elements.length - i - 1] = element;
<mask> });
</s> fix zindex to account for group boundaries (#2065) </s> remove // We go from the next marker to the left (i - 1) to the current one (index)
for (let pos = indicesToMove[i - 1] + 1; pos < index; ++pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos - i] = elements[pos];
</s> add trailingIndex = indicesToMove[indicesToMove.length - 1];
} else {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
trailingIndex = elements.indexOf(groupElements[groupElements.length - 1]);
} else {
trailingIndex = elements.length - 1; </s> remove // We go from the next marker to the right (i - 1) to the current one (index)
for (let pos = reversedIndicesToMove[i - 1] - 1; pos >= index; --pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos + i] = elements[pos];
}
});
</s> add const leadingElements =
direction === "left"
? elements.slice(0, targetIndex)
: elements.slice(0, leadingIndex);
const targetElements = elements.slice(leadingIndex, trailingIndex + 1);
const displacedElements =
direction === "left"
? elements.slice(targetIndex, leadingIndex)
: elements.slice(trailingIndex + 1, targetIndex + 1);
const trailingElements =
direction === "left"
? elements.slice(trailingIndex + 1)
: elements.slice(targetIndex + 1); </s> remove // Let's go through an example
// | |
// [a, b, c, d, e, f, g]
// -->
// [a, b, d, e, g, c, f]
//
// We are going to override all the elements we want to move, so we keep them in an array
// that we will restore at the end.
// [c, f]
//
// From now on, we'll never read those values from the array anymore
// |0 |1
// [a, b, _, d, e, _, g]
//
// The idea is that we want to shift all the elements between the marker 0 and 1
// by one slot to the left.
//
// |0 |1
// [a, b, _, d, e, _, g]
// <- <-
//
// which gives us
//
// |0 |1
// [a, b, d, e, _, _, g]
//
// Now, we need to move all the elements from marker 1 to the end by two (not one)
// slots to the left, which gives us
//
// |0 |1
// [a, b, d, e, _, _, g]
// ^------
//
// which gives us
//
// |0 |1
// [a, b, d, e, g, _, _]
//
// At this point, we can fill back the rightmost elements with the array we saved at
// the beginning
//
// |0 |1
// [a, b, d, e, g, c, f]
//
// And we are done!
export const moveAllRight = <T>(elements: T[], indicesToMove: number[]) => {
const reversedIndicesToMove = indicesToMove.sort(
(a: number, b: number) => b - a,
);
// Copy the elements to move
const rightMostElements = reversedIndicesToMove.map(
(index) => elements[index],
);
indicesToMove = reversedIndicesToMove
// We go from left to right to avoid overriding elements.
.reverse()
// We last element index for the final marker
.concat([elements.length]);
indicesToMove.forEach((index, i) => {
// We skip the first one as it is not paired with anything else
if (i === 0) {
return;
</s> add const shiftElementsToEnd = (
elements: readonly ExcalidrawElement[],
appState: AppState,
direction: "left" | "right",
) => {
const indicesToMove = getIndicesToMove(elements, appState);
const targetElements: ExcalidrawElement[] = [];
const displacedElements: ExcalidrawElement[] = [];
let leadingIndex, trailingIndex;
if (direction === "left") {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
leadingIndex = elements.indexOf(groupElements[0]);
} else {
leadingIndex = 0; </s> remove // Let's go through an example
// | |
// [a, b, c, d, e, f, g]
// -->
// [c, f, a, b, d, e, g]
//
// We are going to override all the elements we want to move, so we keep them in an array
// that we will restore at the end.
// [c, f]
//
// From now on, we'll never read those values from the array anymore
// |1 |0
// [a, b, _, d, e, _, g]
//
// The idea is that we want to shift all the elements between the marker 0 and 1
// by one slot to the right.
//
// |1 |0
// [a, b, _, d, e, _, g]
// -> ->
//
// which gives us
//
// |1 |0
// [a, b, _, _, d, e, g]
//
// Now, we need to move all the elements from marker 1 to the beginning by two (not one)
// slots to the right, which gives us
//
// |1 |0
// [a, b, _, _, d, e, g]
// ---|--^ ^
// ------|
//
// which gives us
//
// |1 |0
// [_, _, a, b, d, e, g]
//
// At this point, we can fill back the leftmost elements with the array we saved at
// the beginning
//
// |1 |0
// [c, f, a, b, d, e, g]
//
// And we are done!
export const moveAllLeft = <T>(elements: T[], indicesToMove: number[]) => {
indicesToMove.sort((a: number, b: number) => a - b);
// Copy the elements to move
const leftMostElements = indicesToMove.map((index) => elements[index]);
const reversedIndicesToMove = indicesToMove
// We go from right to left to avoid overriding elements.
.reverse()
// We add 0 for the final marker
.concat([0]);
reversedIndicesToMove.forEach((index, i) => {
// We skip the first one as it is not paired with anything else
if (i === 0) {
</s> add const shiftElements = (
appState: AppState,
elements: ExcalidrawElement[],
direction: "left" | "right",
) => {
const indicesToMove = getIndicesToMove(elements, appState);
let groupedIndices = toContiguousGroups(indicesToMove);
if (direction === "right") {
groupedIndices = groupedIndices.reverse();
}
groupedIndices.forEach((indices, i) => {
const leadingIndex = indices[0];
const trailingIndex = indices[indices.length - 1];
const boundaryIndex = direction === "left" ? leadingIndex : trailingIndex;
const targetIndex = getTargetIndex(
appState,
elements,
boundaryIndex,
direction,
);
if (targetIndex === -1 || boundaryIndex === targetIndex) { </s> remove export const moveOneLeft = <T>(elements: T[], indicesToMove: number[]) => {
indicesToMove.sort((a: number, b: number) => a - b);
let isSorted = true;
// We go from left to right to avoid overriding the wrong elements
indicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === i;
if (isSorted) {
return;
</s> add /**
* Returns indices of elements to move based on selected elements.
* Includes contiguous deleted elements that are between two selected elements,
* e.g.: [0 (selected), 1 (deleted), 2 (deleted), 3 (selected)]
*/
const getIndicesToMove = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
let selectedIndices: number[] = [];
let deletedIndices: number[] = [];
let includeDeletedIndex = null;
let i = -1;
while (++i < elements.length) {
if (appState.selectedElementIds[elements[i].id]) {
if (deletedIndices.length) {
selectedIndices = selectedIndices.concat(deletedIndices);
deletedIndices = [];
}
selectedIndices.push(i);
includeDeletedIndex = i + 1;
} else if (elements[i].isDeleted && includeDeletedIndex === i) {
includeDeletedIndex = i + 1;
deletedIndices.push(i);
} else {
deletedIndices = [];
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/zindex.ts
|
keep keep keep keep replace keep
|
<mask> rightMostElements.forEach((element, i) => {
<mask> elements[elements.length - i - 1] = element;
<mask> });
<mask>
<mask> return elements;
<mask> };
</s> fix zindex to account for group boundaries (#2065) </s> remove // The final step
rightMostElements.forEach((element, i) => {
elements[elements.length - i - 1] = element;
});
</s> add leadingIndex = indicesToMove[0];
} </s> remove });
</s> add </s> remove // We go from the next marker to the left (i - 1) to the current one (index)
for (let pos = indicesToMove[i - 1] + 1; pos < index; ++pos) {
// We move by 1 the first time, 2 the second... So we can use the index i in the array
elements[pos - i] = elements[pos];
</s> add trailingIndex = indicesToMove[indicesToMove.length - 1];
} else {
if (appState.editingGroupId) {
const groupElements = getElementsInGroup(
elements,
appState.editingGroupId,
);
if (!groupElements.length) {
return elements;
}
trailingIndex = elements.indexOf(groupElements[groupElements.length - 1]);
} else {
trailingIndex = elements.length - 1; </s> remove return elements;
</s> add const toContiguousGroups = (array: number[]) => {
let cursor = 0;
return array.reduce((acc, value, index) => {
if (index > 0 && array[index - 1] !== value - 1) {
cursor = ++cursor;
}
(acc[cursor] || (acc[cursor] = [])).push(value);
return acc;
}, [] as number[][]); </s> remove export const moveOneRight = <T>(elements: T[], indicesToMove: number[]) => {
const reversedIndicesToMove = indicesToMove.sort(
(a: number, b: number) => b - a,
);
let isSorted = true;
// We go from right to left to avoid overriding the wrong elements
reversedIndicesToMove.forEach((index, i) => {
// We don't want to bubble the first elements that are sorted as they are
// already in their correct position
isSorted = isSorted && index === elements.length - i - 1;
if (isSorted) {
return;
</s> add /**
* Returns next candidate index that's available to be moved to. Currently that
* is a non-deleted element, and not inside a group (unless we're editing it).
*/
const getTargetIndex = (
appState: AppState,
elements: ExcalidrawElement[],
boundaryIndex: number,
direction: "left" | "right",
) => {
const sourceElement = elements[boundaryIndex];
const indexFilter = (element: ExcalidrawElement) => {
if (element.isDeleted) {
return false; </s> remove swap(elements, index - 1, index);
});
</s> add }
return selectedIndices;
};
|
https://github.com/excalidraw/excalidraw/commit/d07099aaddd4442f4f40386423664bb9fd8c9294
|
src/zindex.ts
|
keep keep replace replace replace keep keep keep replace replace
|
<mask> },
<mask> "@babel/preset-typescript": {
<mask> "version": "7.12.13",
<mask> "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.12.13.tgz",
<mask> "integrity": "sha512-gYry7CeXwD2wtw5qHzrtzKaShEhOfTmKb4i0ZxeYBcBosN5VuAudsNbjX7Oj5EAfQ3K4s4HsVMQRRcqGsPvs2A==",
<mask> "dev": true,
<mask> "requires": {
<mask> "@babel/helper-plugin-utils": "^7.12.13",
<mask> "@babel/helper-validator-option": "^7.12.11",
<mask> "@babel/plugin-transform-typescript": "^7.12.13"
</s> chore(deps-dev): bump @babel/preset-typescript from 7.12.13 to 7.12.16 in /src/packages/utils (#3024)
Bumps [@babel/preset-typescript](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-typescript) from 7.12.13 to 7.12.16.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.12.16/packages/babel-preset-typescript)
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> </s> remove "@babel/helper-plugin-utils": {
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.12.13.tgz",
"integrity": "sha512-C+10MXCXJLiR6IeG9+Wiejt9jmtFpxUc3MQqCmPY8hfCjyUGl9kT+B2okzEZrtykiwrc4dbCPdDoz0A/HQbDaA==",
"dev": true
},
</s> add </s> remove "version": "7.12.11",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.12.11.tgz",
"integrity": "sha512-TBFCyj939mFSdeX7U7DDj32WtzYY7fDcalgq8v3fBZMNOJQNn7nOYzMaUCiPxPYfCup69mtIpqlKgMZLvQ8Xhw==",
</s> add "version": "7.12.16",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.12.16.tgz",
"integrity": "sha512-uCgsDBPUQDvzr11ePPo4TVEocxj8RXjUVSC/Y8N1YpVAI/XDdUwGJu78xmlGhTxj2ntaWM7n9LQdRtyhOzT2YQ==", </s> remove "@babel/preset-typescript": "7.12.13",
</s> add "@babel/preset-typescript": "7.12.16",
|
https://github.com/excalidraw/excalidraw/commit/d100f38750c62e5e8b3323bbf5d7b228a2b5abab
|
src/packages/utils/package-lock.json
|
keep keep replace replace replace replace replace replace keep replace replace replace keep keep keep
|
<mask> },
<mask> "dependencies": {
<mask> "@babel/helper-plugin-utils": {
<mask> "version": "7.12.13",
<mask> "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.12.13.tgz",
<mask> "integrity": "sha512-C+10MXCXJLiR6IeG9+Wiejt9jmtFpxUc3MQqCmPY8hfCjyUGl9kT+B2okzEZrtykiwrc4dbCPdDoz0A/HQbDaA==",
<mask> "dev": true
<mask> },
<mask> "@babel/helper-validator-option": {
<mask> "version": "7.12.11",
<mask> "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.12.11.tgz",
<mask> "integrity": "sha512-TBFCyj939mFSdeX7U7DDj32WtzYY7fDcalgq8v3fBZMNOJQNn7nOYzMaUCiPxPYfCup69mtIpqlKgMZLvQ8Xhw==",
<mask> "dev": true
<mask> }
<mask> }
</s> chore(deps-dev): bump @babel/preset-typescript from 7.12.13 to 7.12.16 in /src/packages/utils (#3024)
Bumps [@babel/preset-typescript](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-typescript) from 7.12.13 to 7.12.16.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.12.16/packages/babel-preset-typescript)
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> </s> remove "@babel/helper-validator-option": "^7.12.11",
"@babel/plugin-transform-typescript": "^7.12.13"
</s> add "@babel/helper-validator-option": "^7.12.16",
"@babel/plugin-transform-typescript": "^7.12.16" </s> remove "version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.12.13.tgz",
"integrity": "sha512-gYry7CeXwD2wtw5qHzrtzKaShEhOfTmKb4i0ZxeYBcBosN5VuAudsNbjX7Oj5EAfQ3K4s4HsVMQRRcqGsPvs2A==",
</s> add "version": "7.12.16",
"resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.12.16.tgz",
"integrity": "sha512-IrYNrpDSuQfNHeqh7gsJsO35xTGyAyGkI1VxOpBEADFtxCqZ77a1RHbJqM3YJhroj7qMkNMkNtcw0lqeZUrzow==", </s> remove "@babel/preset-typescript": "7.12.13",
</s> add "@babel/preset-typescript": "7.12.16",
|
https://github.com/excalidraw/excalidraw/commit/d100f38750c62e5e8b3323bbf5d7b228a2b5abab
|
src/packages/utils/package-lock.json
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> "@babel/plugin-transform-async-to-generator": "7.12.13",
<mask> "@babel/plugin-transform-runtime": "^7.12.10",
<mask> "@babel/plugin-transform-typescript": "7.12.16",
<mask> "@babel/preset-env": "7.12.13",
<mask> "@babel/preset-typescript": "7.12.13",
<mask> "babel-loader": "8.2.2",
<mask> "babel-plugin-transform-class-properties": "6.24.1",
<mask> "cross-env": "7.0.3",
<mask> "file-loader": "6.2.0",
<mask> "ts-loader": "8.0.15",
</s> chore(deps-dev): bump @babel/preset-typescript from 7.12.13 to 7.12.16 in /src/packages/utils (#3024)
Bumps [@babel/preset-typescript](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-typescript) from 7.12.13 to 7.12.16.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.12.16/packages/babel-preset-typescript)
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> </s> remove "version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.12.13.tgz",
"integrity": "sha512-gYry7CeXwD2wtw5qHzrtzKaShEhOfTmKb4i0ZxeYBcBosN5VuAudsNbjX7Oj5EAfQ3K4s4HsVMQRRcqGsPvs2A==",
</s> add "version": "7.12.16",
"resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.12.16.tgz",
"integrity": "sha512-IrYNrpDSuQfNHeqh7gsJsO35xTGyAyGkI1VxOpBEADFtxCqZ77a1RHbJqM3YJhroj7qMkNMkNtcw0lqeZUrzow==", </s> remove "@babel/helper-validator-option": "^7.12.11",
"@babel/plugin-transform-typescript": "^7.12.13"
</s> add "@babel/helper-validator-option": "^7.12.16",
"@babel/plugin-transform-typescript": "^7.12.16" </s> remove "@babel/helper-plugin-utils": {
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.12.13.tgz",
"integrity": "sha512-C+10MXCXJLiR6IeG9+Wiejt9jmtFpxUc3MQqCmPY8hfCjyUGl9kT+B2okzEZrtykiwrc4dbCPdDoz0A/HQbDaA==",
"dev": true
},
</s> add </s> remove "version": "7.12.11",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.12.11.tgz",
"integrity": "sha512-TBFCyj939mFSdeX7U7DDj32WtzYY7fDcalgq8v3fBZMNOJQNn7nOYzMaUCiPxPYfCup69mtIpqlKgMZLvQ8Xhw==",
</s> add "version": "7.12.16",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.12.16.tgz",
"integrity": "sha512-uCgsDBPUQDvzr11ePPo4TVEocxj8RXjUVSC/Y8N1YpVAI/XDdUwGJu78xmlGhTxj2ntaWM7n9LQdRtyhOzT2YQ==",
|
https://github.com/excalidraw/excalidraw/commit/d100f38750c62e5e8b3323bbf5d7b228a2b5abab
|
src/packages/utils/package.json
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> import { isBindingElement } from "../element/typeChecks";
<mask>
<mask> export const actionFinalize = register({
<mask> name: "finalize",
<mask> perform: (elements, appState, _, { canvas }) => {
<mask> if (appState.editingLinearElement) {
<mask> const {
<mask> elementId,
<mask> startBindingElement,
<mask> endBindingElement,
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove perform: (_elements, appState) => {
</s> add perform: (_elements, appState, _, { focusContainer }) => {
if (appState.showHelpDialog) {
focusContainer();
} </s> add import { focusNearestParent } from "../utils"; </s> add export const focusNearestParent = (element: HTMLInputElement) => {
let parent = element.parentElement;
while (parent) {
if (parent.tabIndex > -1) {
parent.focus();
return;
}
parent = parent.parentElement;
}
}; </s> add focusContainer={focusContainer} </s> remove it("rectangle", async () => {
const { getByToolName, container } = await render(<ExcalidrawApp />);
// select tool
const tool = getByToolName("rectangle");
fireEvent.click(tool);
</s> add it("rectangle", async () => {
const { getByToolName, container } = await render(<ExcalidrawApp />);
// select tool
const tool = getByToolName("rectangle");
fireEvent.click(tool); </s> add focusContainer: () => void;
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/actions/actionFinalize.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> }
<mask>
<mask> let newElements = elements;
<mask> if (window.document.activeElement instanceof HTMLElement) {
<mask> window.document.activeElement.blur();
<mask> }
<mask>
<mask> const multiPointElement = appState.multiElement
<mask> ? appState.multiElement
<mask> : appState.editingElement?.type === "draw"
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove if (isArrowKey(event.key)) {
const step =
(this.state.gridSize &&
(event.shiftKey ? ELEMENT_TRANSLATE_AMOUNT : this.state.gridSize)) ||
(event.shiftKey
? ELEMENT_SHIFT_TRANSLATE_AMOUNT
: ELEMENT_TRANSLATE_AMOUNT);
const selectedElements = this.scene
.getElements()
.filter((element) => this.state.selectedElementIds[element.id]);
let offsetX = 0;
let offsetY = 0;
if (event.key === KEYS.ARROW_LEFT) {
offsetX = -step;
} else if (event.key === KEYS.ARROW_RIGHT) {
offsetX = step;
} else if (event.key === KEYS.ARROW_UP) {
offsetY = -step;
} else if (event.key === KEYS.ARROW_DOWN) {
offsetY = step;
</s> add if (event.code === CODES.NINE) {
this.setState({ isLibraryOpen: !this.state.isLibraryOpen }); </s> remove selectedElements.forEach((element) => {
mutateElement(element, {
x: element.x + offsetX,
y: element.y + offsetY,
});
</s> add if (isArrowKey(event.key)) {
const step =
(this.state.gridSize &&
(event.shiftKey
? ELEMENT_TRANSLATE_AMOUNT
: this.state.gridSize)) ||
(event.shiftKey
? ELEMENT_SHIFT_TRANSLATE_AMOUNT
: ELEMENT_TRANSLATE_AMOUNT);
const selectedElements = this.scene
.getElements()
.filter((element) => this.state.selectedElementIds[element.id]);
let offsetX = 0;
let offsetY = 0;
if (event.key === KEYS.ARROW_LEFT) {
offsetX = -step;
} else if (event.key === KEYS.ARROW_RIGHT) {
offsetX = step;
} else if (event.key === KEYS.ARROW_UP) {
offsetY = -step;
} else if (event.key === KEYS.ARROW_DOWN) {
offsetY = step;
}
selectedElements.forEach((element) => {
mutateElement(element, {
x: element.x + offsetX,
y: element.y + offsetY,
}); </s> remove if (event.code === CODES.NINE) {
this.setState({ isLibraryOpen: !this.state.isLibraryOpen });
}
</s> add if (event[KEYS.CTRL_OR_CMD] && this.state.isBindingEnabled) {
this.setState({ isBindingEnabled: false });
} </s> add focusContainer: () => void; </s> remove private onKeyDown = withBatchedUpdates((event: KeyboardEvent) => {
// normalize `event.key` when CapsLock is pressed #2372
if (
"Proxy" in window &&
((!event.shiftKey && /^[A-Z]$/.test(event.key)) ||
(event.shiftKey && /^[a-z]$/.test(event.key)))
) {
event = new Proxy(event, {
get(ev: any, prop) {
const value = ev[prop];
if (typeof value === "function") {
// fix for Proxies hijacking `this`
return value.bind(ev);
}
return prop === "key"
? // CapsLock inverts capitalization based on ShiftKey, so invert
// it back
event.shiftKey
? ev.key.toUpperCase()
: ev.key.toLowerCase()
: value;
},
});
}
if (
(isWritableElement(event.target) && event.key !== KEYS.ESCAPE) ||
// case: using arrows to move between buttons
(isArrowKey(event.key) && isInputLike(event.target))
) {
return;
}
</s> add private onKeyDown = withBatchedUpdates(
(event: React.KeyboardEvent | KeyboardEvent) => {
// normalize `event.key` when CapsLock is pressed #2372
if (
"Proxy" in window &&
((!event.shiftKey && /^[A-Z]$/.test(event.key)) ||
(event.shiftKey && /^[a-z]$/.test(event.key)))
) {
event = new Proxy(event, {
get(ev: any, prop) {
const value = ev[prop];
if (typeof value === "function") {
// fix for Proxies hijacking `this`
return value.bind(ev);
}
return prop === "key"
? // CapsLock inverts capitalization based on ShiftKey, so invert
// it back
event.shiftKey
? ev.key.toUpperCase()
: ev.key.toLowerCase()
: value;
},
});
} </s> add export const focusNearestParent = (element: HTMLInputElement) => {
let parent = element.parentElement;
while (parent) {
if (parent.tabIndex > -1) {
parent.focus();
return;
}
parent = parent.parentElement;
}
};
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/actions/actionFinalize.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> });
<mask>
<mask> export const actionShortcuts = register({
<mask> name: "toggleShortcuts",
<mask> perform: (_elements, appState) => {
<mask> return {
<mask> appState: {
<mask> ...appState,
<mask> showHelpDialog: !appState.showHelpDialog,
<mask> },
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove perform: (elements, appState, _, { canvas }) => {
</s> add perform: (elements, appState, _, { canvas, focusContainer }) => { </s> remove app: { canvas: HTMLCanvasElement | null },
</s> add app: AppAPI, </s> add export const focusNearestParent = (element: HTMLInputElement) => {
let parent = element.parentElement;
while (parent) {
if (parent.tabIndex > -1) {
parent.focus();
return;
}
parent = parent.parentElement;
}
}; </s> remove private onKeyDown = withBatchedUpdates((event: KeyboardEvent) => {
// normalize `event.key` when CapsLock is pressed #2372
if (
"Proxy" in window &&
((!event.shiftKey && /^[A-Z]$/.test(event.key)) ||
(event.shiftKey && /^[a-z]$/.test(event.key)))
) {
event = new Proxy(event, {
get(ev: any, prop) {
const value = ev[prop];
if (typeof value === "function") {
// fix for Proxies hijacking `this`
return value.bind(ev);
}
return prop === "key"
? // CapsLock inverts capitalization based on ShiftKey, so invert
// it back
event.shiftKey
? ev.key.toUpperCase()
: ev.key.toLowerCase()
: value;
},
});
}
if (
(isWritableElement(event.target) && event.key !== KEYS.ESCAPE) ||
// case: using arrows to move between buttons
(isArrowKey(event.key) && isInputLike(event.target))
) {
return;
}
</s> add private onKeyDown = withBatchedUpdates(
(event: React.KeyboardEvent | KeyboardEvent) => {
// normalize `event.key` when CapsLock is pressed #2372
if (
"Proxy" in window &&
((!event.shiftKey && /^[A-Z]$/.test(event.key)) ||
(event.shiftKey && /^[a-z]$/.test(event.key)))
) {
event = new Proxy(event, {
get(ev: any, prop) {
const value = ev[prop];
if (typeof value === "function") {
// fix for Proxies hijacking `this`
return value.bind(ev);
}
return prop === "key"
? // CapsLock inverts capitalization based on ShiftKey, so invert
// it back
event.shiftKey
? ev.key.toUpperCase()
: ev.key.toLowerCase()
: value;
},
});
} </s> add document.querySelector<HTMLElement>(".excalidraw-container")?.focus(); </s> add handleKeyboardGlobally?: boolean;
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/actions/actionMenu.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> import { MODES } from "../constants";
<mask>
<mask> // This is the <App> component, but for now we don't care about anything but its
<mask> // `canvas` state.
<mask> type App = { canvas: HTMLCanvasElement | null; props: AppProps };
<mask>
<mask> export class ActionManager implements ActionsManagerInterface {
<mask> actions = {} as ActionsManagerInterface["actions"];
<mask>
<mask> updater: (actionResult: ActionResult | Promise<ActionResult>) => void;
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove app: { canvas: HTMLCanvasElement | null },
</s> add app: AppAPI, </s> add type AppAPI = { canvas: HTMLCanvasElement | null; focusContainer(): void };
</s> remove handleKeyDown: (event: KeyboardEvent) => boolean;
</s> add handleKeyDown: (event: React.KeyboardEvent | KeyboardEvent) => boolean; </s> add import { focusNearestParent } from "../utils"; </s> add focusContainer: () => void; </s> remove private onKeyDown = withBatchedUpdates((event: KeyboardEvent) => {
// normalize `event.key` when CapsLock is pressed #2372
if (
"Proxy" in window &&
((!event.shiftKey && /^[A-Z]$/.test(event.key)) ||
(event.shiftKey && /^[a-z]$/.test(event.key)))
) {
event = new Proxy(event, {
get(ev: any, prop) {
const value = ev[prop];
if (typeof value === "function") {
// fix for Proxies hijacking `this`
return value.bind(ev);
}
return prop === "key"
? // CapsLock inverts capitalization based on ShiftKey, so invert
// it back
event.shiftKey
? ev.key.toUpperCase()
: ev.key.toLowerCase()
: value;
},
});
}
if (
(isWritableElement(event.target) && event.key !== KEYS.ESCAPE) ||
// case: using arrows to move between buttons
(isArrowKey(event.key) && isInputLike(event.target))
) {
return;
}
</s> add private onKeyDown = withBatchedUpdates(
(event: React.KeyboardEvent | KeyboardEvent) => {
// normalize `event.key` when CapsLock is pressed #2372
if (
"Proxy" in window &&
((!event.shiftKey && /^[A-Z]$/.test(event.key)) ||
(event.shiftKey && /^[a-z]$/.test(event.key)))
) {
event = new Proxy(event, {
get(ev: any, prop) {
const value = ev[prop];
if (typeof value === "function") {
// fix for Proxies hijacking `this`
return value.bind(ev);
}
return prop === "key"
? // CapsLock inverts capitalization based on ShiftKey, so invert
// it back
event.shiftKey
? ev.key.toUpperCase()
: ev.key.toLowerCase()
: value;
},
});
}
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/actions/manager.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> registerAll(actions: readonly Action[]) {
<mask> actions.forEach((action) => this.registerAction(action));
<mask> }
<mask>
<mask> handleKeyDown(event: KeyboardEvent) {
<mask> const canvasActions = this.app.props.UIOptions.canvasActions;
<mask> const data = Object.values(this.actions)
<mask> .sort((a, b) => (b.keyPriority || 0) - (a.keyPriority || 0))
<mask> .filter(
<mask> (action) =>
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> add handleKeyboardGlobally = false, </s> remove }
if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
isHoldingSpace = true;
setCursor(this.canvas, CURSOR_TYPE.GRABBING);
}
});
</s> add },
); </s> remove expect(h.elements.length).toMatchSnapshot();
h.elements.forEach((element) => expect(element).toMatchSnapshot());
});
</s> add expect(h.elements.length).toMatchSnapshot();
h.elements.forEach((element) => expect(element).toMatchSnapshot());
}); </s> remove expect(h.elements.length).toMatchSnapshot();
h.elements.forEach((element) => expect(element).toMatchSnapshot());
});
</s> add expect(h.elements.length).toMatchSnapshot();
h.elements.forEach((element) => expect(element).toMatchSnapshot());
}); </s> remove expect(h.elements.length).toMatchSnapshot();
h.elements.forEach((element) => expect(element).toMatchSnapshot());
});
</s> add expect(h.elements.length).toMatchSnapshot();
h.elements.forEach((element) => expect(element).toMatchSnapshot());
}); </s> remove expect(h.elements.length).toMatchSnapshot();
h.elements.forEach((element) => expect(element).toMatchSnapshot());
});
</s> add expect(h.elements.length).toMatchSnapshot();
h.elements.forEach((element) => expect(element).toMatchSnapshot());
});
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/actions/manager.tsx
|
keep keep keep add keep keep keep keep keep
|
<mask> syncHistory?: boolean;
<mask> }
<mask> | false;
<mask>
<mask> type ActionFn = (
<mask> elements: readonly ExcalidrawElement[],
<mask> appState: Readonly<AppState>,
<mask> formData: any,
<mask> app: AppAPI,
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove app: { canvas: HTMLCanvasElement | null },
</s> add app: AppAPI, </s> remove event: KeyboardEvent,
</s> add event: React.KeyboardEvent | KeyboardEvent, </s> add handleKeyboardGlobally?: boolean; </s> remove handleKeyDown: (event: KeyboardEvent) => boolean;
</s> add handleKeyDown: (event: React.KeyboardEvent | KeyboardEvent) => boolean; </s> remove type App = { canvas: HTMLCanvasElement | null; props: AppProps };
</s> add type App = {
canvas: HTMLCanvasElement | null;
focusContainer: () => void;
props: AppProps;
}; </s> remove handleKeyDown(event: KeyboardEvent) {
</s> add handleKeyDown(event: React.KeyboardEvent | KeyboardEvent) {
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/actions/types.ts
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> type ActionFn = (
<mask> elements: readonly ExcalidrawElement[],
<mask> appState: Readonly<AppState>,
<mask> formData: any,
<mask> app: { canvas: HTMLCanvasElement | null },
<mask> ) => ActionResult | Promise<ActionResult>;
<mask>
<mask> export type UpdaterFn = (res: ActionResult) => void;
<mask> export type ActionFilterFn = (action: Action) => void;
<mask>
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> add type AppAPI = { canvas: HTMLCanvasElement | null; focusContainer(): void };
</s> remove type App = { canvas: HTMLCanvasElement | null; props: AppProps };
</s> add type App = {
canvas: HTMLCanvasElement | null;
focusContainer: () => void;
props: AppProps;
}; </s> remove handleKeyDown: (event: KeyboardEvent) => boolean;
</s> add handleKeyDown: (event: React.KeyboardEvent | KeyboardEvent) => boolean; </s> add handleKeyboardGlobally?: boolean; </s> remove event: KeyboardEvent,
</s> add event: React.KeyboardEvent | KeyboardEvent, </s> add import { focusNearestParent } from "../utils";
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/actions/types.ts
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> }>;
<mask> perform: ActionFn;
<mask> keyPriority?: number;
<mask> keyTest?: (
<mask> event: KeyboardEvent,
<mask> appState: AppState,
<mask> elements: readonly ExcalidrawElement[],
<mask> ) => boolean;
<mask> contextItemLabel?: string;
<mask> contextItemPredicate?: (
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> add type AppAPI = { canvas: HTMLCanvasElement | null; focusContainer(): void };
</s> remove app: { canvas: HTMLCanvasElement | null },
</s> add app: AppAPI, </s> add handleKeyboardGlobally?: boolean; </s> remove perform: (_elements, appState) => {
</s> add perform: (_elements, appState, _, { focusContainer }) => {
if (appState.showHelpDialog) {
focusContainer();
} </s> remove if (
selectedElements.length === 1 &&
isLinearElement(selectedElements[0])
) {
</s> add </s> remove history.resumeRecording();
this.setState({
editingLinearElement: new LinearElementEditor(
selectedElements[0],
this.scene,
),
</s> add if (
!this.state.editingLinearElement ||
this.state.editingLinearElement.elementId !== selectedElements[0].id
) {
history.resumeRecording();
this.setState({
editingLinearElement: new LinearElementEditor(
selectedElements[0],
this.scene,
),
});
}
} else if (
selectedElements.length === 1 &&
!isLinearElement(selectedElements[0])
) {
const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2,
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/actions/types.ts
|
keep keep keep keep replace keep keep
|
<mask>
<mask> export interface ActionsManagerInterface {
<mask> actions: Record<ActionName, Action>;
<mask> registerAction: (action: Action) => void;
<mask> handleKeyDown: (event: KeyboardEvent) => boolean;
<mask> renderAction: (name: ActionName) => React.ReactElement | null;
<mask> }
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove app: { canvas: HTMLCanvasElement | null },
</s> add app: AppAPI, </s> remove type App = { canvas: HTMLCanvasElement | null; props: AppProps };
</s> add type App = {
canvas: HTMLCanvasElement | null;
focusContainer: () => void;
props: AppProps;
}; </s> add type AppAPI = { canvas: HTMLCanvasElement | null; focusContainer(): void };
</s> add focusContainer, </s> remove handleKeyDown(event: KeyboardEvent) {
</s> add handleKeyDown(event: React.KeyboardEvent | KeyboardEvent) { </s> add handleKeyboardGlobally?: boolean;
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/actions/types.ts
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> const DEFAULT_PASTE_Y = canvasDOMHeight / 2;
<mask>
<mask> return (
<mask> <div
<mask> className={clsx("excalidraw", {
<mask> "excalidraw--view-mode": viewModeEnabled,
<mask> "excalidraw--mobile": this.isMobile,
<mask> })}
<mask> ref={this.excalidrawContainerRef}
<mask> onDrop={this.handleAppOnDrop}
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> add event.stopPropagation(); </s> add event.stopPropagation(); </s> add tabIndex={0}
onKeyDown={
this.props.handleKeyboardGlobally ? undefined : this.onKeyDown
} </s> remove <HelpDialog onClose={() => setAppState({ showHelpDialog: false })} />
</s> add <HelpDialog
onClose={() => {
const helpIcon = document.querySelector(
".help-icon",
)! as HTMLElement;
helpIcon.focus();
setAppState({ showHelpDialog: false });
}}
/> </s> remove const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2,
});
event.preventDefault();
return;
</s> add const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
} </s> remove selectedElements.length === 1 &&
!isLinearElement(selectedElements[0])
</s> add !event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
this.state.draggingElement === null
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep add keep keep keep keep keep keep
|
<mask> ref={this.excalidrawContainerRef}
<mask> onDrop={this.handleAppOnDrop}
<mask> >
<mask> <IsMobileContext.Provider value={this.isMobile}>
<mask> <LayerUI
<mask> canvas={this.canvas}
<mask> appState={this.state}
<mask> setAppState={this.setAppState}
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove className={clsx("excalidraw", {
</s> add className={clsx("excalidraw excalidraw-container", { </s> add tabIndex={0} </s> add export const focusNearestParent = (element: HTMLInputElement) => {
let parent = element.parentElement;
while (parent) {
if (parent.tabIndex > -1) {
parent.focus();
return;
}
parent = parent.parentElement;
}
}; </s> add focusContainer: () => void; </s> add focusContainer(); </s> add focusContainer,
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep keep add keep keep keep keep
|
<mask> }
<mask> libraryReturnUrl={this.props.libraryReturnUrl}
<mask> UIOptions={this.props.UIOptions}
<mask> />
<mask> <div className="excalidraw-textEditorContainer" />
<mask> <div className="excalidraw-contextMenuContainer" />
<mask> {this.state.showStats && (
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove <HelpDialog onClose={() => setAppState({ showHelpDialog: false })} />
</s> add <HelpDialog
onClose={() => {
const helpIcon = document.querySelector(
".help-icon",
)! as HTMLElement;
helpIcon.focus();
setAppState({ showHelpDialog: false });
}}
/> </s> add handleKeyboardGlobally={true} </s> add focusContainer(); </s> add focusContainer={focusContainer} </s> add handleKeyboardGlobally={handleKeyboardGlobally} </s> add event.stopPropagation();
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep add keep keep keep keep keep
|
<mask> }
<mask>
<mask> public getSceneElementsIncludingDeleted = () => {
<mask> return this.scene.getElementsIncludingDeleted();
<mask> };
<mask>
<mask> public getSceneElements = () => {
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> add } finally {
this.focusContainer(); </s> add export const focusNearestParent = (element: HTMLInputElement) => {
let parent = element.parentElement;
while (parent) {
if (parent.tabIndex > -1) {
parent.focus();
return;
}
parent = parent.parentElement;
}
}; </s> add event.stopPropagation(); </s> remove cleanup();
</s> add </s> remove describe("add element to the scene when pointer dragging long enough", () => {
it("rectangle", async () => {
const { getByToolName, container } = await render(<ExcalidrawApp />);
// select tool
const tool = getByToolName("rectangle");
fireEvent.click(tool);
</s> add describe("Test dragCreate", () => {
describe("add element to the scene when pointer dragging long enough", () => {
it("rectangle", async () => {
const { getByToolName, container } = await render(<ExcalidrawApp />);
// select tool
const tool = getByToolName("rectangle");
fireEvent.click(tool); </s> add focusNearestParent(event.target);
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep keep keep add keep keep keep keep keep keep
|
<mask> }
<mask> } catch (error) {
<mask> window.alert(t("alerts.errorLoadingLibrary"));
<mask> console.error(error);
<mask> }
<mask> };
<mask>
<mask> private resetHistory = () => {
<mask> history.clear();
<mask> };
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> add focusNearestParent(event.target); </s> add public focusContainer = () => {
this.excalidrawContainerRef.current?.focus();
};
</s> remove cleanup();
</s> add </s> add export const focusNearestParent = (element: HTMLInputElement) => {
let parent = element.parentElement;
while (parent) {
if (parent.tabIndex > -1) {
parent.focus();
return;
}
parent = parent.parentElement;
}
}; </s> add event.stopPropagation(); </s> remove type App = { canvas: HTMLCanvasElement | null; props: AppProps };
</s> add type App = {
canvas: HTMLCanvasElement | null;
focusContainer: () => void;
props: AppProps;
};
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep keep add keep keep keep keep keep
|
<mask> this.scene.addCallback(this.onSceneUpdated);
<mask> this.addEventListeners();
<mask>
<mask> if ("ResizeObserver" in window && this.excalidrawContainerRef?.current) {
<mask> this.resizeObserver = new ResizeObserver(() => {
<mask> // compute isMobile state
<mask> // ---------------------------------------------------------------------
<mask> const {
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove private onKeyDown = withBatchedUpdates((event: KeyboardEvent) => {
// normalize `event.key` when CapsLock is pressed #2372
if (
"Proxy" in window &&
((!event.shiftKey && /^[A-Z]$/.test(event.key)) ||
(event.shiftKey && /^[a-z]$/.test(event.key)))
) {
event = new Proxy(event, {
get(ev: any, prop) {
const value = ev[prop];
if (typeof value === "function") {
// fix for Proxies hijacking `this`
return value.bind(ev);
}
return prop === "key"
? // CapsLock inverts capitalization based on ShiftKey, so invert
// it back
event.shiftKey
? ev.key.toUpperCase()
: ev.key.toLowerCase()
: value;
},
});
}
if (
(isWritableElement(event.target) && event.key !== KEYS.ESCAPE) ||
// case: using arrows to move between buttons
(isArrowKey(event.key) && isInputLike(event.target))
) {
return;
}
</s> add private onKeyDown = withBatchedUpdates(
(event: React.KeyboardEvent | KeyboardEvent) => {
// normalize `event.key` when CapsLock is pressed #2372
if (
"Proxy" in window &&
((!event.shiftKey && /^[A-Z]$/.test(event.key)) ||
(event.shiftKey && /^[a-z]$/.test(event.key)))
) {
event = new Proxy(event, {
get(ev: any, prop) {
const value = ev[prop];
if (typeof value === "function") {
// fix for Proxies hijacking `this`
return value.bind(ev);
}
return prop === "key"
? // CapsLock inverts capitalization based on ShiftKey, so invert
// it back
event.shiftKey
? ev.key.toUpperCase()
: ev.key.toLowerCase()
: value;
},
});
} </s> add focusContainer, </s> remove history.resumeRecording();
this.setState({
editingLinearElement: new LinearElementEditor(
selectedElements[0],
this.scene,
),
</s> add if (
!this.state.editingLinearElement ||
this.state.editingLinearElement.elementId !== selectedElements[0].id
) {
history.resumeRecording();
this.setState({
editingLinearElement: new LinearElementEditor(
selectedElements[0],
this.scene,
),
});
}
} else if (
selectedElements.length === 1 &&
!isLinearElement(selectedElements[0])
) {
const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2, </s> remove !this.state.editingLinearElement ||
this.state.editingLinearElement.elementId !== selectedElements[0].id
</s> add selectedElements.length === 1 &&
isLinearElement(selectedElements[0]) </s> remove } else if (
!event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
this.state.draggingElement === null
) {
const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
</s> add if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
isHoldingSpace = true;
setCursor(this.canvas, CURSOR_TYPE.GRABBING); </s> remove it("rectangle", async () => {
const { getByToolName, container } = await render(<ExcalidrawApp />);
// select tool
const tool = getByToolName("rectangle");
fireEvent.click(tool);
</s> add it("rectangle", async () => {
const { getByToolName, container } = await render(<ExcalidrawApp />);
// select tool
const tool = getByToolName("rectangle");
fireEvent.click(tool);
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask>
<mask> private addEventListeners() {
<mask> this.removeEventListeners();
<mask> document.addEventListener(EVENT.COPY, this.onCopy);
<mask> document.addEventListener(EVENT.KEYDOWN, this.onKeyDown, false);
<mask> document.addEventListener(EVENT.KEYUP, this.onKeyUp, { passive: true });
<mask> document.addEventListener(
<mask> EVENT.MOUSE_MOVE,
<mask> this.updateCurrentCursorPosition,
<mask> );
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove fireEvent.keyDown(document, { code: CODES.EQUAL, ctrlKey: true });
fireEvent.keyUp(document, { code: CODES.EQUAL, ctrlKey: true });
</s> add fireEvent.keyDown(document, {
code: CODES.EQUAL,
ctrlKey: true,
});
fireEvent.keyUp(document, {
code: CODES.EQUAL,
ctrlKey: true,
}); </s> remove fireEvent.keyDown(document, { code: CODES.MINUS, ctrlKey: true });
fireEvent.keyUp(document, { code: CODES.MINUS, ctrlKey: true });
</s> add fireEvent.keyDown(document, {
code: CODES.MINUS,
ctrlKey: true,
});
fireEvent.keyUp(document, {
code: CODES.MINUS,
ctrlKey: true,
}); </s> remove }
if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
isHoldingSpace = true;
setCursor(this.canvas, CURSOR_TYPE.GRABBING);
}
});
</s> add },
); </s> remove event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
);
</s> add event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
); </s> add } finally {
this.focusContainer(); </s> add focusNearestParent(event.target);
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep replace replace replace replace replace keep keep
|
<mask> // Input handling
<mask>
<mask> private onKeyDown = withBatchedUpdates((event: KeyboardEvent) => {
<mask> // normalize `event.key` when CapsLock is pressed #2372
<mask> if (
<mask> "Proxy" in window &&
<mask> ((!event.shiftKey && /^[A-Z]$/.test(event.key)) ||
<mask> (event.shiftKey && /^[a-z]$/.test(event.key)))
<mask> ) {
<mask> event = new Proxy(event, {
<mask> get(ev: any, prop) {
<mask> const value = ev[prop];
<mask> if (typeof value === "function") {
<mask> // fix for Proxies hijacking `this`
<mask> return value.bind(ev);
<mask> }
<mask> return prop === "key"
<mask> ? // CapsLock inverts capitalization based on ShiftKey, so invert
<mask> // it back
<mask> event.shiftKey
<mask> ? ev.key.toUpperCase()
<mask> : ev.key.toLowerCase()
<mask> : value;
<mask> },
<mask> });
<mask> }
<mask>
<mask> if (
<mask> (isWritableElement(event.target) && event.key !== KEYS.ESCAPE) ||
<mask> // case: using arrows to move between buttons
<mask> (isArrowKey(event.key) && isInputLike(event.target))
<mask> ) {
<mask> return;
<mask> }
<mask>
<mask> if (event.key === KEYS.QUESTION_MARK) {
<mask> this.setState({
<mask> showHelpDialog: true,
<mask> });
<mask> }
<mask>
<mask> if (this.actionManager.handleKeyDown(event)) {
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove if (event.code === CODES.NINE) {
this.setState({ isLibraryOpen: !this.state.isLibraryOpen });
}
</s> add if (event[KEYS.CTRL_OR_CMD] && this.state.isBindingEnabled) {
this.setState({ isBindingEnabled: false });
} </s> remove !this.state.editingLinearElement ||
this.state.editingLinearElement.elementId !== selectedElements[0].id
</s> add selectedElements.length === 1 &&
isLinearElement(selectedElements[0]) </s> remove if (isArrowKey(event.key)) {
const step =
(this.state.gridSize &&
(event.shiftKey ? ELEMENT_TRANSLATE_AMOUNT : this.state.gridSize)) ||
(event.shiftKey
? ELEMENT_SHIFT_TRANSLATE_AMOUNT
: ELEMENT_TRANSLATE_AMOUNT);
const selectedElements = this.scene
.getElements()
.filter((element) => this.state.selectedElementIds[element.id]);
let offsetX = 0;
let offsetY = 0;
if (event.key === KEYS.ARROW_LEFT) {
offsetX = -step;
} else if (event.key === KEYS.ARROW_RIGHT) {
offsetX = step;
} else if (event.key === KEYS.ARROW_UP) {
offsetY = -step;
} else if (event.key === KEYS.ARROW_DOWN) {
offsetY = step;
</s> add if (event.code === CODES.NINE) {
this.setState({ isLibraryOpen: !this.state.isLibraryOpen }); </s> remove } else if (
!event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
this.state.draggingElement === null
) {
const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
</s> add if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
isHoldingSpace = true;
setCursor(this.canvas, CURSOR_TYPE.GRABBING); </s> remove history.resumeRecording();
this.setState({
editingLinearElement: new LinearElementEditor(
selectedElements[0],
this.scene,
),
</s> add if (
!this.state.editingLinearElement ||
this.state.editingLinearElement.elementId !== selectedElements[0].id
) {
history.resumeRecording();
this.setState({
editingLinearElement: new LinearElementEditor(
selectedElements[0],
this.scene,
),
});
}
} else if (
selectedElements.length === 1 &&
!isLinearElement(selectedElements[0])
) {
const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2,
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep keep keep replace replace replace keep replace replace replace keep keep keep keep
|
<mask> });
<mask> }
<mask>
<mask> if (this.actionManager.handleKeyDown(event)) {
<mask> return;
<mask> }
<mask>
<mask> if (this.state.viewModeEnabled) {
<mask> return;
<mask> }
<mask>
<mask> if (event[KEYS.CTRL_OR_CMD] && this.state.isBindingEnabled) {
<mask> this.setState({ isBindingEnabled: false });
<mask> }
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove if (event[KEYS.CTRL_OR_CMD] && this.state.isBindingEnabled) {
this.setState({ isBindingEnabled: false });
}
</s> add if (this.state.viewModeEnabled) {
return;
} </s> remove if (event.code === CODES.NINE) {
this.setState({ isLibraryOpen: !this.state.isLibraryOpen });
}
</s> add if (event[KEYS.CTRL_OR_CMD] && this.state.isBindingEnabled) {
this.setState({ isBindingEnabled: false });
} </s> remove if (event.key === KEYS.QUESTION_MARK) {
this.setState({
showHelpDialog: true,
});
}
</s> add if (
(isWritableElement(event.target) && event.key !== KEYS.ESCAPE) ||
// case: using arrows to move between buttons
(isArrowKey(event.key) && isInputLike(event.target))
) {
return;
} </s> remove } else if (
!event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
this.state.draggingElement === null
) {
const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
</s> add if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
isHoldingSpace = true;
setCursor(this.canvas, CURSOR_TYPE.GRABBING); </s> remove const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2,
});
event.preventDefault();
return;
</s> add const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
}
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep keep keep replace replace replace keep replace replace replace keep
|
<mask> return;
<mask> }
<mask>
<mask> if (event[KEYS.CTRL_OR_CMD] && this.state.isBindingEnabled) {
<mask> this.setState({ isBindingEnabled: false });
<mask> }
<mask>
<mask> if (event.code === CODES.NINE) {
<mask> this.setState({ isLibraryOpen: !this.state.isLibraryOpen });
<mask> }
<mask>
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove if (this.state.viewModeEnabled) {
return;
}
</s> add if (this.actionManager.handleKeyDown(event)) {
return;
} </s> remove if (isArrowKey(event.key)) {
const step =
(this.state.gridSize &&
(event.shiftKey ? ELEMENT_TRANSLATE_AMOUNT : this.state.gridSize)) ||
(event.shiftKey
? ELEMENT_SHIFT_TRANSLATE_AMOUNT
: ELEMENT_TRANSLATE_AMOUNT);
const selectedElements = this.scene
.getElements()
.filter((element) => this.state.selectedElementIds[element.id]);
let offsetX = 0;
let offsetY = 0;
if (event.key === KEYS.ARROW_LEFT) {
offsetX = -step;
} else if (event.key === KEYS.ARROW_RIGHT) {
offsetX = step;
} else if (event.key === KEYS.ARROW_UP) {
offsetY = -step;
} else if (event.key === KEYS.ARROW_DOWN) {
offsetY = step;
</s> add if (event.code === CODES.NINE) {
this.setState({ isLibraryOpen: !this.state.isLibraryOpen }); </s> remove if (this.actionManager.handleKeyDown(event)) {
return;
}
</s> add if (event.key === KEYS.QUESTION_MARK) {
this.setState({
showHelpDialog: true,
});
} </s> remove if (event.key === KEYS.QUESTION_MARK) {
this.setState({
showHelpDialog: true,
});
}
</s> add if (
(isWritableElement(event.target) && event.key !== KEYS.ESCAPE) ||
// case: using arrows to move between buttons
(isArrowKey(event.key) && isInputLike(event.target))
) {
return;
} </s> remove history.resumeRecording();
this.setState({
editingLinearElement: new LinearElementEditor(
selectedElements[0],
this.scene,
),
</s> add if (
!this.state.editingLinearElement ||
this.state.editingLinearElement.elementId !== selectedElements[0].id
) {
history.resumeRecording();
this.setState({
editingLinearElement: new LinearElementEditor(
selectedElements[0],
this.scene,
),
});
}
} else if (
selectedElements.length === 1 &&
!isLinearElement(selectedElements[0])
) {
const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2,
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep replace replace replace replace replace keep keep
|
<mask>
<mask> if (isArrowKey(event.key)) {
<mask> const step =
<mask> (this.state.gridSize &&
<mask> (event.shiftKey ? ELEMENT_TRANSLATE_AMOUNT : this.state.gridSize)) ||
<mask> (event.shiftKey
<mask> ? ELEMENT_SHIFT_TRANSLATE_AMOUNT
<mask> : ELEMENT_TRANSLATE_AMOUNT);
<mask>
<mask> const selectedElements = this.scene
<mask> .getElements()
<mask> .filter((element) => this.state.selectedElementIds[element.id]);
<mask>
<mask> let offsetX = 0;
<mask> let offsetY = 0;
<mask>
<mask> if (event.key === KEYS.ARROW_LEFT) {
<mask> offsetX = -step;
<mask> } else if (event.key === KEYS.ARROW_RIGHT) {
<mask> offsetX = step;
<mask> } else if (event.key === KEYS.ARROW_UP) {
<mask> offsetY = -step;
<mask> } else if (event.key === KEYS.ARROW_DOWN) {
<mask> offsetY = step;
<mask> }
<mask>
<mask> selectedElements.forEach((element) => {
<mask> mutateElement(element, {
<mask> x: element.x + offsetX,
<mask> y: element.y + offsetY,
<mask> });
<mask>
<mask> updateBoundElements(element, {
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove if (event.code === CODES.NINE) {
this.setState({ isLibraryOpen: !this.state.isLibraryOpen });
}
</s> add if (event[KEYS.CTRL_OR_CMD] && this.state.isBindingEnabled) {
this.setState({ isBindingEnabled: false });
} </s> remove event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
);
</s> add event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
); </s> remove } else if (
!event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
this.state.draggingElement === null
) {
const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
</s> add if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
isHoldingSpace = true;
setCursor(this.canvas, CURSOR_TYPE.GRABBING); </s> remove }
if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
isHoldingSpace = true;
setCursor(this.canvas, CURSOR_TYPE.GRABBING);
}
});
</s> add },
); </s> remove const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2,
});
event.preventDefault();
return;
</s> add const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
}
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep keep keep keep replace replace keep keep keep keep keep keep keep keep replace keep keep
|
<mask> x: element.x + offsetX,
<mask> y: element.y + offsetY,
<mask> });
<mask>
<mask> updateBoundElements(element, {
<mask> simultaneouslyUpdated: selectedElements,
<mask> });
<mask> });
<mask>
<mask> this.maybeSuggestBindingForAll(selectedElements);
<mask>
<mask> updateBoundElements(element, {
<mask> simultaneouslyUpdated: selectedElements,
<mask> });
<mask> });
<mask>
<mask> this.maybeSuggestBindingForAll(selectedElements);
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove selectedElements.forEach((element) => {
mutateElement(element, {
x: element.x + offsetX,
y: element.y + offsetY,
});
</s> add if (isArrowKey(event.key)) {
const step =
(this.state.gridSize &&
(event.shiftKey
? ELEMENT_TRANSLATE_AMOUNT
: this.state.gridSize)) ||
(event.shiftKey
? ELEMENT_SHIFT_TRANSLATE_AMOUNT
: ELEMENT_TRANSLATE_AMOUNT);
const selectedElements = this.scene
.getElements()
.filter((element) => this.state.selectedElementIds[element.id]);
let offsetX = 0;
let offsetY = 0;
if (event.key === KEYS.ARROW_LEFT) {
offsetX = -step;
} else if (event.key === KEYS.ARROW_RIGHT) {
offsetX = step;
} else if (event.key === KEYS.ARROW_UP) {
offsetY = -step;
} else if (event.key === KEYS.ARROW_DOWN) {
offsetY = step;
}
selectedElements.forEach((element) => {
mutateElement(element, {
x: element.x + offsetX,
y: element.y + offsetY,
}); </s> remove this.maybeSuggestBindingForAll(selectedElements);
</s> add this.maybeSuggestBindingForAll(selectedElements); </s> remove if (isArrowKey(event.key)) {
const step =
(this.state.gridSize &&
(event.shiftKey ? ELEMENT_TRANSLATE_AMOUNT : this.state.gridSize)) ||
(event.shiftKey
? ELEMENT_SHIFT_TRANSLATE_AMOUNT
: ELEMENT_TRANSLATE_AMOUNT);
const selectedElements = this.scene
.getElements()
.filter((element) => this.state.selectedElementIds[element.id]);
let offsetX = 0;
let offsetY = 0;
if (event.key === KEYS.ARROW_LEFT) {
offsetX = -step;
} else if (event.key === KEYS.ARROW_RIGHT) {
offsetX = step;
} else if (event.key === KEYS.ARROW_UP) {
offsetY = -step;
} else if (event.key === KEYS.ARROW_DOWN) {
offsetY = step;
</s> add if (event.code === CODES.NINE) {
this.setState({ isLibraryOpen: !this.state.isLibraryOpen }); </s> remove event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
);
</s> add event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
); </s> remove selectedElements.length === 1 &&
!isLinearElement(selectedElements[0])
</s> add !event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
this.state.draggingElement === null
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep replace keep replace replace replace replace replace replace keep keep
|
<mask>
<mask> this.maybeSuggestBindingForAll(selectedElements);
<mask>
<mask> event.preventDefault();
<mask> } else if (event.key === KEYS.ENTER) {
<mask> const selectedElements = getSelectedElements(
<mask> this.scene.getElements(),
<mask> this.state,
<mask> );
<mask>
<mask> if (
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove });
</s> add </s> remove if (
selectedElements.length === 1 &&
isLinearElement(selectedElements[0])
) {
</s> add </s> remove } else if (
!event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
this.state.draggingElement === null
) {
const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
</s> add if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
isHoldingSpace = true;
setCursor(this.canvas, CURSOR_TYPE.GRABBING); </s> remove const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2,
});
event.preventDefault();
return;
</s> add const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
} </s> remove if (isArrowKey(event.key)) {
const step =
(this.state.gridSize &&
(event.shiftKey ? ELEMENT_TRANSLATE_AMOUNT : this.state.gridSize)) ||
(event.shiftKey
? ELEMENT_SHIFT_TRANSLATE_AMOUNT
: ELEMENT_TRANSLATE_AMOUNT);
const selectedElements = this.scene
.getElements()
.filter((element) => this.state.selectedElementIds[element.id]);
let offsetX = 0;
let offsetY = 0;
if (event.key === KEYS.ARROW_LEFT) {
offsetX = -step;
} else if (event.key === KEYS.ARROW_RIGHT) {
offsetX = step;
} else if (event.key === KEYS.ARROW_UP) {
offsetY = -step;
} else if (event.key === KEYS.ARROW_DOWN) {
offsetY = step;
</s> add if (event.code === CODES.NINE) {
this.setState({ isLibraryOpen: !this.state.isLibraryOpen });
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep keep keep keep replace replace replace replace keep replace replace
|
<mask> this.scene.getElements(),
<mask> this.state,
<mask> );
<mask>
<mask> if (
<mask> selectedElements.length === 1 &&
<mask> isLinearElement(selectedElements[0])
<mask> ) {
<mask> if (
<mask> !this.state.editingLinearElement ||
<mask> this.state.editingLinearElement.elementId !== selectedElements[0].id
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove history.resumeRecording();
this.setState({
editingLinearElement: new LinearElementEditor(
selectedElements[0],
this.scene,
),
</s> add if (
!this.state.editingLinearElement ||
this.state.editingLinearElement.elementId !== selectedElements[0].id
) {
history.resumeRecording();
this.setState({
editingLinearElement: new LinearElementEditor(
selectedElements[0],
this.scene,
),
});
}
} else if (
selectedElements.length === 1 &&
!isLinearElement(selectedElements[0])
) {
const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2, </s> remove event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
);
</s> add event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
); </s> remove if (event.key === KEYS.QUESTION_MARK) {
this.setState({
showHelpDialog: true,
});
}
</s> add if (
(isWritableElement(event.target) && event.key !== KEYS.ESCAPE) ||
// case: using arrows to move between buttons
(isArrowKey(event.key) && isInputLike(event.target))
) {
return;
} </s> remove const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2,
});
event.preventDefault();
return;
</s> add const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
} </s> remove selectedElements.length === 1 &&
!isLinearElement(selectedElements[0])
</s> add !event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
this.state.draggingElement === null
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep keep keep keep replace replace replace replace replace replace keep keep keep keep keep
|
<mask> if (
<mask> !this.state.editingLinearElement ||
<mask> this.state.editingLinearElement.elementId !== selectedElements[0].id
<mask> ) {
<mask> history.resumeRecording();
<mask> this.setState({
<mask> editingLinearElement: new LinearElementEditor(
<mask> selectedElements[0],
<mask> this.scene,
<mask> ),
<mask> });
<mask> }
<mask> } else if (
<mask> selectedElements.length === 1 &&
<mask> !isLinearElement(selectedElements[0])
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove !this.state.editingLinearElement ||
this.state.editingLinearElement.elementId !== selectedElements[0].id
</s> add selectedElements.length === 1 &&
isLinearElement(selectedElements[0]) </s> remove if (
selectedElements.length === 1 &&
isLinearElement(selectedElements[0])
) {
</s> add </s> remove selectedElements.length === 1 &&
!isLinearElement(selectedElements[0])
</s> add !event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
this.state.draggingElement === null </s> remove const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2,
});
event.preventDefault();
return;
</s> add const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
} </s> remove event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
);
</s> add event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
); </s> remove if (event.key === KEYS.QUESTION_MARK) {
this.setState({
showHelpDialog: true,
});
}
</s> add if (
(isWritableElement(event.target) && event.key !== KEYS.ESCAPE) ||
// case: using arrows to move between buttons
(isArrowKey(event.key) && isInputLike(event.target))
) {
return;
}
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep keep keep add keep keep keep keep keep
|
<mask> this.startTextEditing({
<mask> sceneX: selectedElement.x + selectedElement.width / 2,
<mask> sceneY: selectedElement.y + selectedElement.height / 2,
<mask> });
<mask> }
<mask> } else if (
<mask> !event.ctrlKey &&
<mask> !event.altKey &&
<mask> !event.metaKey &&
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove selectedElements.length === 1 &&
!isLinearElement(selectedElements[0])
</s> add !event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
this.state.draggingElement === null </s> remove const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2,
});
event.preventDefault();
return;
</s> add const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
} </s> remove history.resumeRecording();
this.setState({
editingLinearElement: new LinearElementEditor(
selectedElements[0],
this.scene,
),
</s> add if (
!this.state.editingLinearElement ||
this.state.editingLinearElement.elementId !== selectedElements[0].id
) {
history.resumeRecording();
this.setState({
editingLinearElement: new LinearElementEditor(
selectedElements[0],
this.scene,
),
});
}
} else if (
selectedElements.length === 1 &&
!isLinearElement(selectedElements[0])
) {
const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2, </s> remove } else if (
!event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
this.state.draggingElement === null
) {
const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
</s> add if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
isHoldingSpace = true;
setCursor(this.canvas, CURSOR_TYPE.GRABBING); </s> remove selectedElements.forEach((element) => {
mutateElement(element, {
x: element.x + offsetX,
y: element.y + offsetY,
});
</s> add if (isArrowKey(event.key)) {
const step =
(this.state.gridSize &&
(event.shiftKey
? ELEMENT_TRANSLATE_AMOUNT
: this.state.gridSize)) ||
(event.shiftKey
? ELEMENT_SHIFT_TRANSLATE_AMOUNT
: ELEMENT_TRANSLATE_AMOUNT);
const selectedElements = this.scene
.getElements()
.filter((element) => this.state.selectedElementIds[element.id]);
let offsetX = 0;
let offsetY = 0;
if (event.key === KEYS.ARROW_LEFT) {
offsetX = -step;
} else if (event.key === KEYS.ARROW_RIGHT) {
offsetX = step;
} else if (event.key === KEYS.ARROW_UP) {
offsetY = -step;
} else if (event.key === KEYS.ARROW_DOWN) {
offsetY = step;
}
selectedElements.forEach((element) => {
mutateElement(element, {
x: element.x + offsetX,
y: element.y + offsetY,
}); </s> remove event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
);
</s> add event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
);
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep replace replace keep replace replace replace replace replace replace replace keep keep
|
<mask> } else if (
<mask> selectedElements.length === 1 &&
<mask> !isLinearElement(selectedElements[0])
<mask> ) {
<mask> const selectedElement = selectedElements[0];
<mask> this.startTextEditing({
<mask> sceneX: selectedElement.x + selectedElement.width / 2,
<mask> sceneY: selectedElement.y + selectedElement.height / 2,
<mask> });
<mask> event.preventDefault();
<mask> return;
<mask> }
<mask> } else if (
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> add event.preventDefault();
return; </s> remove history.resumeRecording();
this.setState({
editingLinearElement: new LinearElementEditor(
selectedElements[0],
this.scene,
),
</s> add if (
!this.state.editingLinearElement ||
this.state.editingLinearElement.elementId !== selectedElements[0].id
) {
history.resumeRecording();
this.setState({
editingLinearElement: new LinearElementEditor(
selectedElements[0],
this.scene,
),
});
}
} else if (
selectedElements.length === 1 &&
!isLinearElement(selectedElements[0])
) {
const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2, </s> remove event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
);
</s> add event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
); </s> remove } else if (
!event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
this.state.draggingElement === null
) {
const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
</s> add if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
isHoldingSpace = true;
setCursor(this.canvas, CURSOR_TYPE.GRABBING); </s> remove if (
selectedElements.length === 1 &&
isLinearElement(selectedElements[0])
) {
</s> add
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace keep replace replace replace replace replace replace keep keep keep keep
|
<mask> });
<mask> event.preventDefault();
<mask> return;
<mask> }
<mask> } else if (
<mask> !event.ctrlKey &&
<mask> !event.altKey &&
<mask> !event.metaKey &&
<mask> this.state.draggingElement === null
<mask> ) {
<mask> const shape = findShapeByKey(event.key);
<mask> if (shape) {
<mask> this.selectShapeTool(shape);
<mask> } else if (event.key === KEYS.Q) {
<mask> this.toggleLock();
<mask> }
<mask> }
<mask> if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
<mask> isHoldingSpace = true;
<mask> setCursor(this.canvas, CURSOR_TYPE.GRABBING);
<mask> }
<mask> });
<mask>
<mask> private onKeyUp = withBatchedUpdates((event: KeyboardEvent) => {
<mask> if (event.key === KEYS.SPACE) {
<mask> if (this.state.elementType === "selection") {
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove const selectedElement = selectedElements[0];
this.startTextEditing({
sceneX: selectedElement.x + selectedElement.width / 2,
sceneY: selectedElement.y + selectedElement.height / 2,
});
event.preventDefault();
return;
</s> add const shape = findShapeByKey(event.key);
if (shape) {
this.selectShapeTool(shape);
} else if (event.key === KEYS.Q) {
this.toggleLock();
} </s> remove event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
);
</s> add event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getElements(),
this.state,
); </s> remove selectedElements.length === 1 &&
!isLinearElement(selectedElements[0])
</s> add !event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
this.state.draggingElement === null </s> remove if (isArrowKey(event.key)) {
const step =
(this.state.gridSize &&
(event.shiftKey ? ELEMENT_TRANSLATE_AMOUNT : this.state.gridSize)) ||
(event.shiftKey
? ELEMENT_SHIFT_TRANSLATE_AMOUNT
: ELEMENT_TRANSLATE_AMOUNT);
const selectedElements = this.scene
.getElements()
.filter((element) => this.state.selectedElementIds[element.id]);
let offsetX = 0;
let offsetY = 0;
if (event.key === KEYS.ARROW_LEFT) {
offsetX = -step;
} else if (event.key === KEYS.ARROW_RIGHT) {
offsetX = step;
} else if (event.key === KEYS.ARROW_UP) {
offsetY = -step;
} else if (event.key === KEYS.ARROW_DOWN) {
offsetY = step;
</s> add if (event.code === CODES.NINE) {
this.setState({ isLibraryOpen: !this.state.isLibraryOpen }); </s> remove selectedElements.forEach((element) => {
mutateElement(element, {
x: element.x + offsetX,
y: element.y + offsetY,
});
</s> add if (isArrowKey(event.key)) {
const step =
(this.state.gridSize &&
(event.shiftKey
? ELEMENT_TRANSLATE_AMOUNT
: this.state.gridSize)) ||
(event.shiftKey
? ELEMENT_SHIFT_TRANSLATE_AMOUNT
: ELEMENT_TRANSLATE_AMOUNT);
const selectedElements = this.scene
.getElements()
.filter((element) => this.state.selectedElementIds[element.id]);
let offsetX = 0;
let offsetY = 0;
if (event.key === KEYS.ARROW_LEFT) {
offsetX = -step;
} else if (event.key === KEYS.ARROW_RIGHT) {
offsetX = step;
} else if (event.key === KEYS.ARROW_UP) {
offsetY = -step;
} else if (event.key === KEYS.ARROW_DOWN) {
offsetY = step;
}
selectedElements.forEach((element) => {
mutateElement(element, {
x: element.x + offsetX,
y: element.y + offsetY,
});
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep keep keep keep replace keep keep keep keep keep
|
<mask> if (!isHoldingSpace) {
<mask> setCursorForShape(this.canvas, elementType);
<mask> }
<mask> if (isToolIcon(document.activeElement)) {
<mask> document.activeElement.blur();
<mask> }
<mask> if (!isLinearElementType(elementType)) {
<mask> this.setState({ suggestedBindings: [] });
<mask> }
<mask> if (elementType !== "selection") {
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> remove if (event[KEYS.CTRL_OR_CMD] && this.state.isBindingEnabled) {
this.setState({ isBindingEnabled: false });
}
</s> add if (this.state.viewModeEnabled) {
return;
} </s> remove if (this.state.viewModeEnabled) {
return;
}
</s> add if (this.actionManager.handleKeyDown(event)) {
return;
} </s> remove if (event.code === CODES.NINE) {
this.setState({ isLibraryOpen: !this.state.isLibraryOpen });
}
</s> add if (event[KEYS.CTRL_OR_CMD] && this.state.isBindingEnabled) {
this.setState({ isBindingEnabled: false });
} </s> remove if (event.key === KEYS.QUESTION_MARK) {
this.setState({
showHelpDialog: true,
});
}
</s> add if (
(isWritableElement(event.target) && event.key !== KEYS.ESCAPE) ||
// case: using arrows to move between buttons
(isArrowKey(event.key) && isInputLike(event.target))
) {
return;
} </s> remove if (this.actionManager.handleKeyDown(event)) {
return;
}
</s> add if (event.key === KEYS.QUESTION_MARK) {
this.setState({
showHelpDialog: true,
});
} </s> remove }
if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
isHoldingSpace = true;
setCursor(this.canvas, CURSOR_TYPE.GRABBING);
}
});
</s> add },
);
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep add keep keep keep keep
|
<mask> setCursorForShape(this.canvas, this.state.elementType);
<mask> }
<mask> }),
<mask> element,
<mask> });
<mask> // deselect all other elements when inserting text
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> add &:focus {
outline: none;
}
</s> remove document.activeElement.blur();
</s> add this.focusContainer(); </s> remove describe("add element to the scene when pointer dragging long enough", () => {
it("rectangle", async () => {
const { getByToolName, container } = await render(<ExcalidrawApp />);
// select tool
const tool = getByToolName("rectangle");
fireEvent.click(tool);
</s> add describe("Test dragCreate", () => {
describe("add element to the scene when pointer dragging long enough", () => {
it("rectangle", async () => {
const { getByToolName, container } = await render(<ExcalidrawApp />);
// select tool
const tool = getByToolName("rectangle");
fireEvent.click(tool); </s> remove exports[`add element to the scene when pointer dragging long enough arrow 1`] = `1`;
</s> add exports[`Test dragCreate add element to the scene when pointer dragging long enough arrow 1`] = `1`; </s> remove exports[`add element to the scene when pointer dragging long enough arrow 2`] = `
</s> add exports[`Test dragCreate add element to the scene when pointer dragging long enough arrow 2`] = ` </s> remove private onKeyDown = withBatchedUpdates((event: KeyboardEvent) => {
// normalize `event.key` when CapsLock is pressed #2372
if (
"Proxy" in window &&
((!event.shiftKey && /^[A-Z]$/.test(event.key)) ||
(event.shiftKey && /^[a-z]$/.test(event.key)))
) {
event = new Proxy(event, {
get(ev: any, prop) {
const value = ev[prop];
if (typeof value === "function") {
// fix for Proxies hijacking `this`
return value.bind(ev);
}
return prop === "key"
? // CapsLock inverts capitalization based on ShiftKey, so invert
// it back
event.shiftKey
? ev.key.toUpperCase()
: ev.key.toLowerCase()
: value;
},
});
}
if (
(isWritableElement(event.target) && event.key !== KEYS.ESCAPE) ||
// case: using arrows to move between buttons
(isArrowKey(event.key) && isInputLike(event.target))
) {
return;
}
</s> add private onKeyDown = withBatchedUpdates(
(event: React.KeyboardEvent | KeyboardEvent) => {
// normalize `event.key` when CapsLock is pressed #2372
if (
"Proxy" in window &&
((!event.shiftKey && /^[A-Z]$/.test(event.key)) ||
(event.shiftKey && /^[a-z]$/.test(event.key)))
) {
event = new Proxy(event, {
get(ev: any, prop) {
const value = ev[prop];
if (typeof value === "function") {
// fix for Proxies hijacking `this`
return value.bind(ev);
}
return prop === "key"
? // CapsLock inverts capitalization based on ShiftKey, so invert
// it back
event.shiftKey
? ev.key.toUpperCase()
: ev.key.toLowerCase()
: value;
},
});
}
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/App.tsx
|
keep keep add keep keep keep keep
|
<mask> onClose();
<mask> }
<mask> event.nativeEvent.stopImmediatePropagation();
<mask> };
<mask>
<mask> return (
<mask> <div
</s> feat: Bind keyboard events to the current excalidraw container and add handleKeyboardGlobally prop to allow host to bind to document (#3430)
* fix: Bind keyboard events to excalidraw container
* fix cases around blurring
* fix modal rendering so keyboard shortcuts work on modal as well
* Revert "fix modal rendering so keyboard shortcuts work on modal as well"
This reverts commit 2c8ec6be8eff7d308591467fe2c33cfbca16138f.
* Attach keyboard event in react way so we need not handle portals separately (modals)
* dnt propagate esc event when modal shown
* focus the container when help dialog closed with shift+?
* focus the help icon when help dialog on close triggered
* move focusNearestTabbableParent to util
* rename util to focusNearestParent and remove outline from excal and modal
* Add prop bindKeyGlobally to decide if keyboard events should be binded to document and allow it in excal app, revert tests
* fix
* focus container after installing library, reset library and closing error dialog
* fix tests and create util to focus container
* Add excalidraw-container class to focus on the container
* pass focus container to library to focus current instance of excal
* update docs
* remove util as it wont be used anywhere
* fix propagation not being stopped for React keyboard handling
* tweak reamde
Co-authored-by: David Luzar <[email protected]>
* tweak changelog
* rename prop to handleKeyboardGlobally
Co-authored-by: dwelle <[email protected]> </s> add event.stopPropagation(); </s> add document.querySelector<HTMLElement>(".excalidraw-container")?.focus(); </s> add event.stopPropagation(); </s> remove className={clsx("excalidraw", {
</s> add className={clsx("excalidraw excalidraw-container", { </s> add focusContainer={this.focusContainer} </s> add public focusContainer = () => {
this.excalidrawContainerRef.current?.focus();
};
|
https://github.com/excalidraw/excalidraw/commit/d126d04d179ec10aca05bf7b3b2a0fb3eb04f739
|
src/components/ColorPicker.tsx
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.