fix #914 Add render diagram keyboard shortcut

This commit is contained in:
Sidharth Vinod
2022-08-12 13:36:24 +05:30
parent 2d5dfee074
commit 736dd46831
4 changed files with 22 additions and 2 deletions
+9
View File
@@ -21,6 +21,15 @@ describe('Auto sync tests', () => {
cy.getLocalStorage('codeStore').snapshot();
});
it('should update diagram when shortcut is used', () => {
cy.contains('Auto sync').click();
cy.get('#view').should('not.have.class', 'outOfSync');
getEditor().type(' C --> Test');
cy.get('#view').should('have.class', 'outOfSync');
getEditor().type(`{${cmd}}{enter}`);
cy.get('#view').should('not.have.class', 'outOfSync');
});
it('should show/hide sync button with auto sync', () => {
cy.get('[data-cy=sync]').should('not.exist');
cy.contains('Auto sync').click();
+9
View File
@@ -2,6 +2,7 @@
import type { EditorEvents } from '$lib/types';
import { stateStore } from '$lib/util/state';
import { themeStore } from '$lib/util/theme';
import { syncDiagram } from '$lib/util/util';
import type monaco from 'monaco-editor';
import { createEventDispatcher, onMount } from 'svelte';
import initEditor from 'monaco-mermaid';
@@ -66,6 +67,14 @@
text
});
});
editor.addAction({
id: 'mermaid-render-diagram',
label: 'Render Diagram',
keybindings: [Monaco.KeyMod.CtrlCmd | Monaco.KeyCode.Enter],
run: function () {
syncDiagram();
}
});
Monaco?.editor.setTheme($themeStore.isDark ? 'mermaid-dark' : 'mermaid');
const resizeObserver = new ResizeObserver((entries) => {
editor.layout({
+2
View File
@@ -22,3 +22,5 @@ export const initHandler = async (): Promise<void> => {
await initAnalytics();
analytics?.page();
};
export const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0;
+2 -2
View File
@@ -7,7 +7,7 @@
import Card from '$lib/components/card/card.svelte';
import History from '$lib/components/history/history.svelte';
import { updateCode, updateConfig, inputStateStore, stateStore } from '$lib/util/state';
import { initHandler, syncDiagram } from '$lib/util/util';
import { initHandler, isMac, syncDiagram } from '$lib/util/util';
import { onMount } from 'svelte';
import type { EditorUpdateEvent, State, Tab, DocConfig } from '$lib/types';
import { base } from '$app/paths';
@@ -154,7 +154,7 @@
{#if !$stateStore.autoSync}
<button
class="btn btn-secondary btn-xs mr-1"
title="Sync Diagram"
title="Sync Diagram ({isMac ? 'Cmd' : 'Ctrl'} + Enter)"
data-cy="sync"
on:click={syncDiagram}><i class="fas fa-sync" /></button>
{/if}