@neo4j-cypher/codemirror
Advanced tools
Comparing version 1.0.0-next.9 to 1.0.0-next.10
@@ -57,3 +57,3 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
theme: THEME_LIGHT, | ||
tooltipAbsolute: false, | ||
tooltipAbsolute: true, | ||
value: "" | ||
@@ -60,0 +60,0 @@ }; |
@@ -27,3 +27,3 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import { autocompletion as autocompletionExtension, completionKeymap, completionStatus, acceptCompletion } from "@codemirror/autocomplete"; | ||
import { history as historyExtension, defaultKeymap, historyKeymap, indentMore, indentLess } from "@codemirror/commands"; | ||
import { history as historyExtension, defaultKeymap, historyKeymap, indentMore, indentLess, insertTab } from "@codemirror/commands"; | ||
import { StreamLanguage, indentOnInput, foldKeymap, syntaxHighlighting, HighlightStyle } from "@codemirror/language"; | ||
@@ -39,3 +39,3 @@ import { linter, lintKeymap } from "@codemirror/lint"; | ||
import { typeMarkerField, addTypeMarkerEffect, clearTypeMarkersEffect } from "./cypher-state-definitions"; | ||
import { getStateEditorSupport, getStateLineCount, getStateValue, getStatePositionAbsoluteForLineColumn, getStatePositionForAbsolute } from "./cypher-state-selectors"; | ||
import { getStateEditorSupport, getStateLineCount, getStateValue, getStatePositionAbsoluteForLineColumn, getStatePositionForAbsolute, getStatePositionAnchor } from "./cypher-state-selectors"; | ||
const typeMarkerTheme = EditorView.baseTheme({ | ||
@@ -241,6 +241,23 @@ // ".cm-underline": { textDecoration: "underline 3px red" } | ||
export const historyExtensions = [historyExtension()]; | ||
const whitespaceRegex = /[\s]/; | ||
export const isAtStartOfLine = state => { | ||
const positionObject = getStatePositionAnchor(state); | ||
const value = getStateValue(state); | ||
const lineStart = positionObject.position - positionObject.column; | ||
for (let i = 0; i < positionObject.column; i++) { | ||
if (!whitespaceRegex.test(value.charAt(lineStart + i))) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
const runTab = (view, event) => { | ||
const status = completionStatus(view.state); | ||
if (status === null) { | ||
indentMore(view); | ||
if (isAtStartOfLine(view.state)) { | ||
indentMore(view); | ||
} else { | ||
insertTab(view); | ||
} | ||
event && event.preventDefault(); | ||
} else if (status === "active") { | ||
@@ -253,4 +270,5 @@ acceptCompletion(view); | ||
const status = completionStatus(view.state); | ||
if (status === null) { | ||
if (status === null && isAtStartOfLine(view.state)) { | ||
indentLess(view); | ||
event && event.preventDefault(); | ||
} | ||
@@ -257,0 +275,0 @@ }; |
@@ -23,2 +23,3 @@ /* | ||
import { editorSupportField } from "./cypher-state-definitions"; | ||
export const getStatePositionAnchorAbsolute = state => state.selection.main.anchor; | ||
export const getStatePositionAbsolute = state => state.selection.main.head; | ||
@@ -48,2 +49,3 @@ export const getStateEditorSupport = state => state.field(editorSupportField, false); | ||
export const getStatePosition = state => getStatePositionForAbsolute(state, getStatePositionAbsolute(state)); | ||
export const getStatePositionAnchor = state => getStatePositionForAbsolute(state, getStatePositionAnchorAbsolute(state)); | ||
export const getStatePositionForAny = (state, positionValue) => { | ||
@@ -50,0 +52,0 @@ let position = null; |
@@ -68,3 +68,3 @@ "use strict"; | ||
theme: THEME_LIGHT, | ||
tooltipAbsolute: false, | ||
tooltipAbsolute: true, | ||
value: "" | ||
@@ -71,0 +71,0 @@ }; |
@@ -7,3 +7,3 @@ "use strict"; | ||
}); | ||
exports.useStickyAutocompleteExtensions = exports.useNoLintExtensions = exports.useLintExtensions = exports.useAutocompleteExtensions = exports.tabKeyExtensions = exports.syntaxCSS = exports.readableExtensions = exports.readOnlyNoCursorExtensions = exports.readOnlyExtensions = exports.lineWrappingExtensions = exports.historyExtensions = exports.getTooltipAbsoluteExtensions = exports.getThemeExtensions = exports.getTabKeyExtensions = exports.getReadableExtensions = exports.getReadOnlyExtensions = exports.getPlaceholderExtensions = exports.getLintExtensions = exports.getLineWrappingExtensions = exports.getLineNumbersExtensions = exports.getHistoryExtensions = exports.getAutocompleteExtensions = exports.fixColors = exports.domListener = exports.cypherLinter = exports.cypherLineNumbers = exports.cypherLanguage = exports.cypherCompletion = void 0; | ||
exports.useStickyAutocompleteExtensions = exports.useNoLintExtensions = exports.useLintExtensions = exports.useAutocompleteExtensions = exports.tabKeyExtensions = exports.syntaxCSS = exports.readableExtensions = exports.readOnlyNoCursorExtensions = exports.readOnlyExtensions = exports.lineWrappingExtensions = exports.isAtStartOfLine = exports.historyExtensions = exports.getTooltipAbsoluteExtensions = exports.getThemeExtensions = exports.getTabKeyExtensions = exports.getReadableExtensions = exports.getReadOnlyExtensions = exports.getPlaceholderExtensions = exports.getLintExtensions = exports.getLineWrappingExtensions = exports.getLineNumbersExtensions = exports.getHistoryExtensions = exports.getAutocompleteExtensions = exports.fixColors = exports.domListener = exports.cypherLinter = exports.cypherLineNumbers = exports.cypherLanguage = exports.cypherCompletion = void 0; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
@@ -234,6 +234,24 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); | ||
exports.historyExtensions = historyExtensions; | ||
const whitespaceRegex = /[\s]/; | ||
const isAtStartOfLine = state => { | ||
const positionObject = (0, _cypherStateSelectors.getStatePositionAnchor)(state); | ||
const value = (0, _cypherStateSelectors.getStateValue)(state); | ||
const lineStart = positionObject.position - positionObject.column; | ||
for (let i = 0; i < positionObject.column; i++) { | ||
if (!whitespaceRegex.test(value.charAt(lineStart + i))) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
exports.isAtStartOfLine = isAtStartOfLine; | ||
const runTab = (view, event) => { | ||
const status = (0, _autocomplete.completionStatus)(view.state); | ||
if (status === null) { | ||
(0, _commands.indentMore)(view); | ||
if (isAtStartOfLine(view.state)) { | ||
(0, _commands.indentMore)(view); | ||
} else { | ||
(0, _commands.insertTab)(view); | ||
} | ||
event && event.preventDefault(); | ||
} else if (status === "active") { | ||
@@ -246,4 +264,5 @@ (0, _autocomplete.acceptCompletion)(view); | ||
const status = (0, _autocomplete.completionStatus)(view.state); | ||
if (status === null) { | ||
if (status === null && isAtStartOfLine(view.state)) { | ||
(0, _commands.indentLess)(view); | ||
event && event.preventDefault(); | ||
} | ||
@@ -250,0 +269,0 @@ }; |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.getStateValue = exports.getStatePositionForAny = exports.getStatePositionForAbsolute = exports.getStatePositionAbsoluteForLineColumn = exports.getStatePositionAbsolute = exports.getStatePosition = exports.getStateLineObjectForLine = exports.getStateLineObjectForAbsolute = exports.getStateLineCount = exports.getStateLength = exports.getStateEditorSupport = void 0; | ||
exports.getStateValue = exports.getStatePositionForAny = exports.getStatePositionForAbsolute = exports.getStatePositionAnchorAbsolute = exports.getStatePositionAnchor = exports.getStatePositionAbsoluteForLineColumn = exports.getStatePositionAbsolute = exports.getStatePosition = exports.getStateLineObjectForLine = exports.getStateLineObjectForAbsolute = exports.getStateLineCount = exports.getStateLength = exports.getStateEditorSupport = void 0; | ||
var _cypherCodemirrorBase = require("./cypher-codemirror-base"); | ||
@@ -30,2 +30,4 @@ var _cypherStateDefinitions = require("./cypher-state-definitions"); | ||
const getStatePositionAnchorAbsolute = state => state.selection.main.anchor; | ||
exports.getStatePositionAnchorAbsolute = getStatePositionAnchorAbsolute; | ||
const getStatePositionAbsolute = state => state.selection.main.head; | ||
@@ -65,2 +67,4 @@ exports.getStatePositionAbsolute = getStatePositionAbsolute; | ||
exports.getStatePosition = getStatePosition; | ||
const getStatePositionAnchor = state => getStatePositionForAbsolute(state, getStatePositionAnchorAbsolute(state)); | ||
exports.getStatePositionAnchor = getStatePositionAnchor; | ||
const getStatePositionForAny = (state, positionValue) => { | ||
@@ -67,0 +71,0 @@ let position = null; |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "1.0.0-next.9", | ||
"version": "1.0.0-next.10", | ||
"author": "Neo4j Inc.", | ||
@@ -12,0 +12,0 @@ "license": "GPL-3.0", |
@@ -532,3 +532,3 @@ /** | ||
* | ||
* @defaultValue false | ||
* @defaultValue true | ||
*/ | ||
@@ -535,0 +535,0 @@ tooltipAbsolute?: boolean; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
147593
3646