From 1d8f36dcb3e0f4903d9378dc81e953d1a3dbee03 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Fri, 22 Jul 2022 12:06:42 +0200 Subject: [PATCH 1/5] cherry pick editor --- apps/remix-ide/src/app/editor/editor.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide/src/app/editor/editor.js b/apps/remix-ide/src/app/editor/editor.js index 97dc63f988..7725387688 100644 --- a/apps/remix-ide/src/app/editor/editor.js +++ b/apps/remix-ide/src/app/editor/editor.js @@ -13,7 +13,7 @@ const profile = { name: 'editor', description: 'service - editor', version: packageJson.version, - methods: ['highlight', 'discardHighlight', 'clearAnnotations', 'addAnnotation', 'gotoLine', 'revealRange', 'getCursorPosition'] + methods: ['highlight', 'discardHighlight', 'clearAnnotations', 'addLineText', 'discardLineTexts', 'addAnnotation', 'gotoLine', 'revealRange', 'getCursorPosition', 'open'] } class Editor extends Plugin { @@ -26,8 +26,8 @@ class Editor extends Plugin { remixDark: 'remix-dark' } - this.registeredDecorations = { sourceAnnotationsPerFile: {}, markerPerFile: {} } - this.currentDecorations = { sourceAnnotationsPerFile: {}, markerPerFile: {} } + this.registeredDecorations = { sourceAnnotationsPerFile: {}, markerPerFile: {}, lineTextPerFile: {} } + this.currentDecorations = { sourceAnnotationsPerFile: {}, markerPerFile: {}, lineTextPerFile: {} } // Init this.event = new EventManager() @@ -567,6 +567,18 @@ class Editor extends Plugin { this.clearDecorationsByPlugin(session, from, 'markerPerFile', this.registeredDecorations, this.currentDecorations) } } + + async addLineText (lineText, filePath) { + filePath = filePath || this.currentFile + await this.addDecoration(lineText, filePath, 'lineTextPerFile') + } + + discardLineTexts() { + const { from } = this.currentRequest + for (const session in this.sessions) { + this.clearDecorationsByPlugin(session, from, 'lineTextPerFile', this.registeredDecorations, this.currentDecorations) + } + } } module.exports = Editor From 5523be0f89e90957c43fc78a8a667c7fdf60a805 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Fri, 22 Jul 2022 12:33:37 +0200 Subject: [PATCH 2/5] types --- .../editor/src/lib/remix-ui-editor.tsx | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index 46a5e76d9b..59637a2438 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -4,6 +4,7 @@ import Editor, { loader } from '@monaco-editor/react' import { reducerActions, reducerListener, initialState } from './actions/editor' import { language, conf } from './syntax' import { cairoLang, cairoConf } from './cairoSyntax' +import { IMarkdownString } from 'monaco-editor' import './remix-ui-editor.css' import { loadTypes } from './web-types' @@ -39,6 +40,25 @@ type sourceMarker = { hide: boolean } +export type lineText = { + position: { + start: { + line: number + column: number + }, + end: { + line: number + column: number + } + }, + from?: string // plugin name + content: string + className: string + afterContentClassName: string + hide: boolean, + hoverMessage: IMarkdownString | IMarkdownString[] +} + loader.config({ paths: { vs: 'assets/js/monaco-editor/dev/vs' } }) export type DecorationsReturn = { @@ -259,7 +279,7 @@ export const EditorUI = (props: EditorUIProps) => { } }, [props.currentFile]) - const convertToMonacoDecoration = (decoration: sourceAnnotation | sourceMarker, typeOfDecoration: string) => { + const convertToMonacoDecoration = (decoration: lineText | sourceAnnotation | sourceMarker, typeOfDecoration: string) => { if (typeOfDecoration === 'sourceAnnotationsPerFile') { decoration = decoration as sourceAnnotation return { @@ -289,6 +309,19 @@ export const EditorUI = (props: EditorUIProps) => { } } } + if (typeOfDecoration === 'lineTextPerFile') { + const lineTextDecoration = decoration as lineText + return { + type: typeOfDecoration, + range: new monacoRef.current.Range(lineTextDecoration.position.start.line + 1, lineTextDecoration.position.start.column + 1, lineTextDecoration.position.start.line + 1, 1024), + options: { + after: { content: ` ${lineTextDecoration.content}`, inlineClassName: `${lineTextDecoration.className}` }, + afterContentClassName: `${lineTextDecoration.afterContentClassName}`, + hoverMessage : lineTextDecoration.hoverMessage + }, + + } + } } props.editorAPI.clearDecorationsByPlugin = (filePath: string, plugin: string, typeOfDecoration: string, registeredDecorations: any, currentDecorations: any) => { From 17b7615ceac15c187906761b1a381c57168c0102 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Fri, 22 Jul 2022 12:34:23 +0200 Subject: [PATCH 3/5] rm open call --- apps/remix-ide/src/app/editor/editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/src/app/editor/editor.js b/apps/remix-ide/src/app/editor/editor.js index 7725387688..34b9c172e5 100644 --- a/apps/remix-ide/src/app/editor/editor.js +++ b/apps/remix-ide/src/app/editor/editor.js @@ -13,7 +13,7 @@ const profile = { name: 'editor', description: 'service - editor', version: packageJson.version, - methods: ['highlight', 'discardHighlight', 'clearAnnotations', 'addLineText', 'discardLineTexts', 'addAnnotation', 'gotoLine', 'revealRange', 'getCursorPosition', 'open'] + methods: ['highlight', 'discardHighlight', 'clearAnnotations', 'addLineText', 'discardLineTexts', 'addAnnotation', 'gotoLine', 'revealRange', 'getCursorPosition'] } class Editor extends Plugin { From 315652f12939f68ee309a9c6a64ec9b78842eaa4 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Fri, 22 Jul 2022 13:28:22 +0200 Subject: [PATCH 4/5] add tests --- .../src/tests/editor_line_text.test.ts | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 apps/remix-ide-e2e/src/tests/editor_line_text.test.ts diff --git a/apps/remix-ide-e2e/src/tests/editor_line_text.test.ts b/apps/remix-ide-e2e/src/tests/editor_line_text.test.ts new file mode 100644 index 0000000000..d0d079cf68 --- /dev/null +++ b/apps/remix-ide-e2e/src/tests/editor_line_text.test.ts @@ -0,0 +1,69 @@ +'use strict' + +import { NightwatchBrowser } from 'nightwatch' +import init from '../helpers/init' + +module.exports = { + + before: function (browser: NightwatchBrowser, done: VoidFunction) { + init(browser, done, 'http://127.0.0.1:8080', true) + }, + 'Should add line texts': function (browser: NightwatchBrowser) { + browser + .openFile('contracts') + .openFile('contracts/1_Storage.sol') + .addFile('scripts/addlinetext.ts', {content: addLineText}) + .pause(2000) + .executeScript('remix.exeCurrent()') + .pause(4000) + .openFile('contracts/1_Storage.sol') + .useXpath() + .waitForElementVisible("//*[@class='view-line' and contains(.,'contract')]//span//span[contains(.,'mylinetext1')]") + .waitForElementVisible("//*[@class='view-line' and contains(.,'function')]//span//span[contains(.,'mylinetext2')]") + } +} + +const addLineText = ` +(async () => { + + await remix.call('editor', 'discardLineTexts' as any) + let linetext = { + content: 'mylinetext1', + position: { + start: { + line: 9, + column: 1, + } + }, + hide: false, + className: 'text-muted small', + afterContentClassName: 'text-muted small fas fa-gas-pump pl-4', + hoverMessage: [{ + value: 'hovering1', + }, + ], + } + + await remix.call('editor', 'addLineText' as any, linetext, 'contracts/1_Storage.sol') + + + linetext = { + content: 'mylinetext2', + position: { + start: { + line: 17, + column: 1, + } + }, + hide: false, + className: 'text-muted small', + afterContentClassName: 'text-muted small fas fa-gas-pump pl-4', + hoverMessage: [{ + value: 'hovering2', + }, + ], + } + + await remix.call('editor', 'addLineText' as any, linetext, 'contracts/1_Storage.sol') + +})()` \ No newline at end of file From 65ef95b7882183ab1776af48e7d8b34785770118 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Tue, 9 Aug 2022 12:24:45 +0200 Subject: [PATCH 5/5] update test --- apps/remix-ide-e2e/src/tests/editor_line_text.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/editor_line_text.test.ts b/apps/remix-ide-e2e/src/tests/editor_line_text.test.ts index d0d079cf68..afff1c8f28 100644 --- a/apps/remix-ide-e2e/src/tests/editor_line_text.test.ts +++ b/apps/remix-ide-e2e/src/tests/editor_line_text.test.ts @@ -13,8 +13,8 @@ module.exports = { .openFile('contracts') .openFile('contracts/1_Storage.sol') .addFile('scripts/addlinetext.ts', {content: addLineText}) - .pause(2000) - .executeScript('remix.exeCurrent()') + .pause(4000) + .executeScriptInTerminal('remix.exeCurrent()') .pause(4000) .openFile('contracts/1_Storage.sol') .useXpath()