Skip to content

Commit

Permalink
Merge pull request #216 from eccenca/feature/supportPathAutoCompletio…
Browse files Browse the repository at this point in the history
…nInEditorsUpdated-CMEM-5454

Improve CodeAutocompleteField (CMEM-5454)
  • Loading branch information
haschek authored Nov 13, 2024
2 parents ae79a80 + 048ef68 commit 9885f99
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/components/Application/_config.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

/// should be already imported
//@import '~@carbon/react/scss/colors';
// @import '~@carbon/react/scss/colors';

/*
//----------------------------------------------------------------------------
Expand Down
29 changes: 21 additions & 8 deletions src/components/AutoSuggestion/AutoSuggestion.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,50 @@
}
}

.#{$eccgui}-autosuggestion__inputfield {
background-color: $eccgui-color-textfield-background;
}

.#{$eccgui}-singlelinecodeeditor {
position: relative;
padding: 0 1px;
padding: 0;

[class^="cm-theme"] {
width: 100%;
}

&:has(.cm-editor.cm-focused) {
box-shadow: input-transition-shadow($input-shadow-color-focus, true), $input-box-shadow-focus;
}

.cm-editor {
top: 2px;
top: 1px;
height: calc(#{$eccgui-size-textfield-height-regular} - 2px);
padding: 0;
margin: 0;
overflow: hidden;
background-color: transparent;
border-radius: 0;
box-shadow: none;

&.cm-focused {
outline: none;
box-shadow: none;
}

.cm-scroller {
height: 100%;
padding: 0;
margin: 0;
overflow: auto hidden !important;
}

.CodeMirror-vscrollbar {
display: none !important;
}

.cm-content {
vertical-align: middle;
display: flex;
flex-direction: column;
justify-content: center;
height: 100%;
min-height: 100%;
padding: 0;
border: none;
}

Expand Down
35 changes: 20 additions & 15 deletions src/components/AutoSuggestion/AutoSuggestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,25 @@ const AutoSuggestion = ({
[]
);

const codeEditor = React.useMemo(() => {
return <ExtendedCodeEditor
mode={mode}
setCM={setCM}
onChange={handleChange}
onCursorChange={handleCursorChange}
initialValue={initialValue}
onFocusChange={handleInputFocus}
onKeyDown={handleInputEditorKeyPress}
enableTab={useTabForCompletions}
placeholder={placeholder}
onSelection={onSelection}
showScrollBar={showScrollBar}
multiline={multiline}
onMouseDown={handleInputMouseDown}
/>

}, [mode, setCM, handleChange, initialValue, useTabForCompletions, placeholder, showScrollBar, multiline, handleInputMouseDown])

const hasError = !!value.current && !pathIsValid && !pathValidationPending;
const autoSuggestionInput = (
<div
Expand Down Expand Up @@ -642,21 +661,7 @@ const AutoSuggestion = ({
/>
}
>
<ExtendedCodeEditor
mode={mode}
setCM={setCM}
onChange={handleChange}
onCursorChange={handleCursorChange}
initialValue={initialValue}
onFocusChange={handleInputFocus}
onKeyDown={handleInputEditorKeyPress}
enableTab={useTabForCompletions}
placeholder={placeholder}
onSelection={onSelection}
showScrollBar={showScrollBar}
multiline={multiline}
onMouseDown={handleInputMouseDown}
/>
{codeEditor}
</ContextOverlay>
{!!value.current && (
<span className={BlueprintClassNames.INPUT_ACTION} ref={inputactionsDisplayed}>
Expand Down
3 changes: 1 addition & 2 deletions src/components/TextField/textfield.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
// own vars
$eccgui-size-textfield-height-small: $eccgui-size-block-whitespace * 2 !default;
$eccgui-size-textfield-height-regular: $eccgui-size-textfield-height-small * $eccgui-size-type-levelratio !default;
$eccgui-size-textfield-height-large: $eccgui-size-textfield-height-regular * $eccgui-size-type-levelratio *
$eccgui-size-type-levelratio !default;
$eccgui-size-textfield-height-large: $eccgui-size-textfield-height-regular * $eccgui-size-type-levelratio * $eccgui-size-type-levelratio !default;
$eccgui-size-textfield-padding-horizontal-regular: $eccgui-size-inline-whitespace !default;
$eccgui-size-textfield-padding-horizontal-small: $eccgui-size-inline-whitespace * 0.5 !default;
$eccgui-typo-textfield-fontweight: $eccgui-font-weight-regular !default;
Expand Down
1 change: 0 additions & 1 deletion src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@
@import "./Typography/typography";
@import "./Workspace/workspace";
@import "./Accordion/accordion";
@import "./AutoSuggestion/AutoSuggestion";
@import "./Badge/badge";
@import "./PropertyValuePair/propertyvalue";
7 changes: 1 addition & 6 deletions src/extensions/_index.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
@import "./react-flow/react-flow";

/*
CodeMirror styles are already included by the base component styles
because it is used as lib for elements there already.
@import "./codemirror/codemirror";
*/

@import "./../components/AutoSuggestion/AutoSuggestion"; // the whole element should moved to extensions forlder
@import "./uppy/fileupload";
17 changes: 10 additions & 7 deletions src/extensions/codemirror/CodeMirror.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React, { AllHTMLAttributes, useRef } from "react";
import React, { useRef } from "react";
import { defaultKeymap, indentWithTab } from "@codemirror/commands";
import { foldKeymap } from "@codemirror/language";
import { EditorState, Extension } from "@codemirror/state";
import { DOMEventHandlers, EditorView, KeyBinding, keymap, Rect, ViewUpdate } from "@codemirror/view";
//CodeMirror
import { minimalSetup } from "codemirror";

import { markField } from "../../components/AutoSuggestion/extensions/markText";
//constants
import { CLASSPREFIX as eccgui } from "../../configuration/constants";

//hooks
Expand All @@ -27,6 +25,7 @@ import {
adaptedLineNumbers,
adaptedPlaceholder,
} from "./tests/codemirrorTestHelper";

export interface CodeEditorProps {
// Is called with the editor instance that allows access via the CodeMirror API
setEditorView?: (editor: EditorView | undefined) => any;
Expand Down Expand Up @@ -92,7 +91,7 @@ export interface CodeEditorProps {
/** Long lines are wrapped and displayed on multiple lines */
wrapLines?: boolean;

outerDivAttributes?: Partial<AllHTMLAttributes<HTMLDivElement>>;
outerDivAttributes?: Omit<React.HTMLAttributes<HTMLDivElement>, "id" | "data-test-id">;

/**
* Size in spaces that is used for a tabulator key.
Expand Down Expand Up @@ -276,11 +275,15 @@ export const CodeEditor = ({

return (
<div
id={id ? id : `codemirror-${name}`}
{...outerDivAttributes}
// overwrite/extend some attributes
id={id ? id : name ? `codemirror-${name}` : undefined}
ref={parent}
data-test-id="codemirror-wrapper"
className={`${eccgui}-codeeditor ${eccgui}-codeeditor--mode-${mode}`}
{...outerDivAttributes}
className={
`${eccgui}-codeeditor ${eccgui}-codeeditor--mode-${mode}` +
(outerDivAttributes?.className ? ` ${outerDivAttributes?.className}` : "")
}
/>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/codemirror/_codemirror.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ $eccgui-color-codeeditor-background: $eccgui-color-textfield-background !default
// fix size to prevent wrong calculation of other elements
padding: 0;
margin: 1px;
cursor: text;
}

&.cm-focused {
Expand All @@ -54,6 +53,7 @@ $eccgui-color-codeeditor-background: $eccgui-color-textfield-background !default
}

.cm-content {
cursor: text;
border-right-width: $eccgui-size-inline-whitespace !important;
}

Expand Down
1 change: 0 additions & 1 deletion src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ $prefix-carbon: $prefix;
// == Load basic components styles =============================================

@import "./components";
@import "./extensions/codemirror/codemirror";

// set more readable variable for prefix
$prefix-eccgui: $eccgui;
Expand Down

0 comments on commit 9885f99

Please sign in to comment.