Skip to content

Commit

Permalink
fix(code-editor): add disable scroll option for code editor (#2258)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsahitya committed Oct 29, 2024
1 parent 62ccccc commit 3e8584d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
7 changes: 5 additions & 2 deletions libs/components/src/code-editor/code-editor.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ export default {
theme: 'cv-light',
code: sqlContent,
language: 'sql',
disableScroll: false,
},
};

const Template = ({ theme, language, code }) => {
const Template = ({ theme, language, code, disableScroll }) => {
return `
<div style="width: 800px; height: 100%">
<cv-code-editor language="${language}" theme="${theme}" code="${code}">
<cv-code-editor language="${language}" theme="${theme}" code="${code}" ${
disableScroll ? 'disableScroll' : ''
}>
</cv-code-editor>
</div>
`;
Expand Down
14 changes: 10 additions & 4 deletions libs/components/src/code-editor/code-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class CovalentCodeEditor extends LitElement {
* Code entered into the editor
*/
@property() code?: string;
/**
* Disable scroll bar and set the editor height based on content
*/
@property({ type: Boolean, reflect: true }) disableScroll?: boolean = false;
/**
* Options that can be set for the editor
*/
Expand Down Expand Up @@ -155,10 +159,12 @@ export class CovalentCodeEditor extends LitElement {
);
});

// Adjust the height of the editor when content changes, to avoid vertical scroll bar
this.editor?.onDidContentSizeChange(() => {
this.adjustHeight();
});
if (this.disableScroll) {
// Adjust the height of the editor when content changes, to avoid vertical scroll bar
this.editor?.onDidContentSizeChange(() => {
this.adjustHeight();
});
}

this.adjustHeight();

Expand Down
1 change: 1 addition & 0 deletions libs/components/src/notebook-cell/notebook-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export class CovalentNotebookCell extends LitElement {
.language="${this.language}"
.options="${this.editorOptions}"
.theme="${this.editorTheme}"
disableScroll
></cv-code-editor>`
: html`<cv-code-snippet hideHeader .language="${this.language}"
>${this.code}</cv-code-snippet
Expand Down

0 comments on commit 3e8584d

Please sign in to comment.