-
Notifications
You must be signed in to change notification settings - Fork 0
134 feature code editor 2 #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KamyaPA
wants to merge
16
commits into
main
Choose a base branch
from
134-feature-code-editor-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d62573d
CodeJar setup but not scaling
KamyaPA c738f1d
scrollbars
DenFlyvendeGed 9a5d459
Working linenumbers chrome is a bit wack but working
KamyaPA 1522446
fixed chrome and webkit
KamyaPA 494914b
new fix
KamyaPA 4f8ad12
added modes
KamyaPA 682d7a6
Merge branch 'main' into 134-feature-code-editor
KamyaPA 1165e64
missed some conflicts
KamyaPA 8ec44c9
fixed editor
KamyaPA 15dbca1
Merge branch 'main' into 134-feature-code-editor-2
KamyaPA 48e15e5
Readded tests
KamyaPA e2b9b98
yarn format
KamyaPA ed8cec5
Changed css
DenFlyvendeGed 35799d9
Merge branch 'main' into 134-feature-code-editor-2
KamyaPA bd1452f
fixed merge fail
KamyaPA d650881
Added yarn.lock from main branch
KamyaPA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <script lang="ts"> | ||
| import Editor from "../editor/Editor.svelte"; | ||
| import SvgView from "$lib/components/svgView/SvgView.svelte"; | ||
| import { CanvasModes, canvasModes } from "./state"; | ||
| </script> | ||
|
|
||
| <Editor isHidden={$canvasModes !== CanvasModes.Editor} /> | ||
| <SvgView isHidden={$canvasModes !== CanvasModes.Draw} /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| <script lang="ts"> | ||
| import { Draw, Code } from "svelte-google-materialdesign-icons"; | ||
| import SvgButton from "../buttons/SvgButton.svelte"; | ||
|
|
||
| import { | ||
| CanvasModes, | ||
| CanvasSupports, | ||
| canvasModes, | ||
| canvasSupports, | ||
| } from "./state"; | ||
|
|
||
| let supports = CanvasSupports.OnlyEditor; | ||
| let mode = CanvasModes.Editor; | ||
|
|
||
| canvasModes.subscribe((newMode) => { | ||
| mode = newMode; | ||
| }); | ||
|
|
||
| canvasSupports.subscribe((newSupports) => { | ||
| supports = newSupports; | ||
| }); | ||
| </script> | ||
|
|
||
| <nav id="canvas-nav"> | ||
| <div class="buttons"> | ||
| {#if supports === CanvasSupports.Both && mode !== CanvasModes.Draw} | ||
| <SvgButton | ||
| icon={Draw} | ||
| id="toggle-draw" | ||
| size={30} | ||
| click={() => { | ||
| canvasModes.set(CanvasModes.Draw); | ||
| }} | ||
| /> | ||
| {/if} | ||
| {#if supports === CanvasSupports.Both && mode !== CanvasModes.Editor} | ||
| <SvgButton | ||
| icon={Code} | ||
| id="toggle-editor" | ||
| size={30} | ||
| click={() => { | ||
| canvasModes.set(CanvasModes.Editor); | ||
| }} | ||
| /> | ||
| {/if} | ||
| </div> | ||
| </nav> | ||
|
|
||
| <style> | ||
| #canvas-nav { | ||
| display: flex; | ||
| justify-content: flex-end; | ||
| align-items: center; | ||
| min-height: 5em; | ||
| padding: 0 1em; | ||
| background-color: var(--canvas-topbar-color); | ||
| } | ||
|
|
||
| .buttons { | ||
| color: var(--navigationbar-text-color); | ||
| background: none; | ||
| border: none; | ||
| display: flex; | ||
| } | ||
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { Component, GlobalDeclarations, System } from "$lib/classes/automaton"; | ||
| import { activeView } from "$lib/globalState/activeProject"; | ||
| import { writable } from "svelte/store"; | ||
| import { editor } from "$lib/components/editor/state"; | ||
|
|
||
| export enum CanvasModes { | ||
| Draw, | ||
| Editor, | ||
| } | ||
|
|
||
| export enum CanvasSupports { | ||
| OnlyDraw, | ||
| OnlyEditor, | ||
| Both, | ||
| } | ||
|
|
||
| export const canvasSupports = writable(CanvasSupports.OnlyEditor); | ||
| export const canvasModes = writable(CanvasModes.Editor); | ||
|
|
||
| canvasSupports.subscribe((newSupports) => { | ||
| canvasModes.update((currentMode) => { | ||
| if ( | ||
| newSupports == CanvasSupports.OnlyEditor && | ||
| currentMode == CanvasModes.Draw | ||
| ) | ||
| return CanvasModes.Editor; | ||
| else if ( | ||
| newSupports == CanvasSupports.OnlyDraw && | ||
| currentMode == CanvasModes.Editor | ||
| ) | ||
| return CanvasModes.Draw; | ||
| else return currentMode; | ||
| }); | ||
| }); | ||
|
|
||
| activeView.subscribe((view) => { | ||
| if (view instanceof Component) { | ||
| canvasSupports.set(CanvasSupports.Both); | ||
| editor.change.set(view.declarations); | ||
| editor.push.set((code: string) => { | ||
| view.declarations = code; | ||
| }); | ||
| } else if (view instanceof System) { | ||
| canvasSupports.set(CanvasSupports.OnlyDraw); | ||
| } else if (view instanceof GlobalDeclarations) { | ||
| canvasSupports.set(CanvasSupports.OnlyEditor); | ||
| editor.change.set(view.declarations); | ||
| editor.push.set((code: string) => { | ||
| view.declarations = code; | ||
| }); | ||
| } else { | ||
| canvasSupports.set(CanvasSupports.OnlyEditor); | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| <script lang="ts"> | ||
| import { onMount } from "svelte"; | ||
| import { default as hljs } from "highlight.js"; | ||
| import { editor } from "./state"; | ||
|
|
||
| export let isHidden: boolean; | ||
| let editorDiv: HTMLElement; | ||
|
|
||
| hljs.registerLanguage("ecdar", () => { | ||
| return { | ||
| case_insensitive: false, | ||
| keywords: ["clock", "broadcast", "chan"], | ||
| contains: [hljs.COMMENT("/\\*", "\\*/"), hljs.COMMENT("//", "\\n")], | ||
| }; | ||
| }); | ||
|
|
||
| function createLineNr(i: number) { | ||
| let num = document.createElement("div"); | ||
| num.innerHTML = String(i); | ||
| num.classList.add("editor-linenum"); | ||
| return num; | ||
| } | ||
|
|
||
| onMount(async () => { | ||
| let { CodeJar } = await import("codejar"); | ||
| let node = document.createElement("div"); | ||
| node.style.float = "right"; | ||
| node.style.width = | ||
| "calc(100% - var(--editor-lineno-width) - var(--editor-lineno-margin-right))"; | ||
| node.classList.add("editor-text"); | ||
|
|
||
| let linenr = document.createElement("div"); | ||
| linenr.style.display = "flex"; | ||
| linenr.style.flexDirection = "column"; | ||
| linenr.style.justifyContent = "start"; | ||
| linenr.style.float = "left"; | ||
| linenr.style.width = "var(--editor-lineno-width)"; | ||
|
|
||
| function updateLines(text: string) { | ||
| linenr.innerHTML = ""; | ||
| if (!text.includes("\n")) { | ||
| linenr.appendChild(createLineNr(1)); | ||
| return; | ||
| } | ||
| // Fixes line numbers in chrome and webkit | ||
| let substr = text.substring(text.length - 1); | ||
| if (substr == "\n") { | ||
| text = text.substring(0, text.length - 1); | ||
| } | ||
| linenr.appendChild(createLineNr(1)); | ||
| let lines = 1; | ||
| for (let i = 0; i <= text.length; i++) | ||
| if (text[i] == "\n") linenr.appendChild(createLineNr(++lines)); | ||
| } | ||
|
|
||
| function updateCode(node: HTMLElement, code: string) { | ||
| updateLines(code); | ||
| let highlight = hljs.highlight(code, { language: "ecdar" }).value; | ||
| node.innerHTML = highlight; | ||
| } | ||
|
|
||
| editor.change.subscribe((newCode) => { | ||
| updateCode(node, newCode); | ||
| }); | ||
|
|
||
| updateLines(""); | ||
| CodeJar( | ||
| node, | ||
| (n: HTMLElement) => { | ||
| let code = n.textContent as string; | ||
| editor.push.update((push) => (push(code), push)); | ||
| updateCode(n, code); | ||
| }, | ||
| { | ||
| history: false, | ||
| addClosing: false, | ||
| }, | ||
| ); | ||
|
|
||
| node.style.overflowY = "visible"; | ||
| editorDiv.appendChild(linenr); | ||
| editorDiv.appendChild(node); | ||
| editorDiv.style.visibility = isHidden ? "hidden" : "visible"; | ||
| }); | ||
| </script> | ||
|
|
||
| <div | ||
| id="editor" | ||
| bind:this={editorDiv} | ||
| style={isHidden ? "visibility:hidden; height:0px;" : "visibility:visible;"} | ||
| /> | ||
|
|
||
| <style> | ||
| :global(:root) { | ||
| --editor-lineno-width: 2.5em; | ||
| --editor-lineno-margin-right: 0.3em; | ||
| } | ||
|
|
||
| #editor { | ||
| width: 100%; | ||
| height: 200%; | ||
| max-width: 80vw; | ||
| overflow: auto; | ||
| } | ||
|
|
||
| :global(.editor-text) { | ||
| height: 100%; | ||
| text-wrap: nowrap !important; | ||
| font-family: monospace; | ||
| font-size: 20px; | ||
| } | ||
|
|
||
| :global(.hljs-keyword) { | ||
| color: var(--editor-keyword-color); | ||
| font-family: monospace; | ||
| } | ||
|
|
||
| :global(.hljs-comment) { | ||
| color: var(--editor-comment-color); | ||
| font-family: monospace; | ||
| } | ||
|
|
||
| :global(.editor-linenum) { | ||
| font-size: 20px; | ||
| background-color: var(--canvas-topbar-color); | ||
| border-color: var(--canvas-topbar-color); | ||
| font-family: monospace; | ||
| text-align: right; | ||
| padding-right: var(--editor-lineno-margin-right); | ||
| } | ||
| </style> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { writable } from "svelte/store"; | ||
|
|
||
| /** | ||
| * A handler for the editor | ||
| * */ | ||
| export const editor = { | ||
| /** | ||
| * The writable containing the function that runs whenever the editor pushes | ||
| * */ | ||
| push: writable((s: string) => { | ||
| s; | ||
| }), | ||
| /** | ||
| * The writable that whenever set overwrites what is displayed in the editor | ||
| * */ | ||
| change: writable(""), | ||
| }; |
6 changes: 5 additions & 1 deletion
6
src/lib/components/project/globalDeclaration/GlobalDeclaration.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { writable } from "svelte/store"; | ||
|
|
||
| export const showSettings = writable(false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.