From a6b5295df50733a9b9883ff6e9a6de3d2154a971 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Mon, 13 Jun 2022 23:05:23 +0530 Subject: [PATCH] chore: revert indented line wrap due to issues with mobile (fixes hoppscotch/internal-issues#9) --- .../helpers/editor/codemirror.ts | 5 ++-- .../editor/extensions/IndentedLineWrap.ts | 27 ------------------- 2 files changed, 2 insertions(+), 30 deletions(-) delete mode 100644 packages/hoppscotch-app/helpers/editor/extensions/IndentedLineWrap.ts diff --git a/packages/hoppscotch-app/helpers/editor/codemirror.ts b/packages/hoppscotch-app/helpers/editor/codemirror.ts index 7e6ed56f..e591dbde 100644 --- a/packages/hoppscotch-app/helpers/editor/codemirror.ts +++ b/packages/hoppscotch-app/helpers/editor/codemirror.ts @@ -38,7 +38,6 @@ import { Completer } from "./completion" import { LinterDefinition } from "./linting/linter" import { basicSetup, baseTheme, baseHighlightStyle } from "./themes/baseTheme" import { HoppEnvironmentPlugin } from "./extensions/HoppEnvironment" -import { IndentedLineWrapPlugin } from "./extensions/IndentedLineWrap" // TODO: Migrate from legacy mode type ExtendedEditorConfig = { @@ -238,7 +237,7 @@ export function useCodemirror( ), lineWrapping.of( options.extendedEditorConfig.lineWrapping - ? [IndentedLineWrapPlugin] + ? [EditorView.lineWrapping] : [] ), keymap.of([ @@ -325,7 +324,7 @@ export function useCodemirror( (newMode) => { view.value?.dispatch({ effects: lineWrapping.reconfigure( - newMode ? [EditorView.lineWrapping, IndentedLineWrapPlugin] : [] + newMode ? [EditorView.lineWrapping] : [] ), }) } diff --git a/packages/hoppscotch-app/helpers/editor/extensions/IndentedLineWrap.ts b/packages/hoppscotch-app/helpers/editor/extensions/IndentedLineWrap.ts deleted file mode 100644 index 5ad2519c..00000000 --- a/packages/hoppscotch-app/helpers/editor/extensions/IndentedLineWrap.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { EditorView } from "@codemirror/view" - -const WrappedLineIndenter = EditorView.updateListener.of((update) => { - const view = update.view - const charWidth = view.defaultCharacterWidth - const lineHeight = view.defaultLineHeight - const basePadding = 10 - - view.viewportLines((line) => { - const domAtPos = view.domAtPos(line.from) - - const lineCount = (line.bottom - line.top) / lineHeight - - if (lineCount <= 1) return - - const belowPadding = basePadding * charWidth - - const node = domAtPos.node as HTMLElement - node.style.textIndent = `-${belowPadding - charWidth + 1}px` - node.style.paddingLeft = `${belowPadding}px` - }) -}) - -export const IndentedLineWrapPlugin = [ - EditorView.lineWrapping, - WrappedLineIndenter, -]