Skip to content

Commit

Permalink
Source code mode: When the text area is resized, the number of visibl…
Browse files Browse the repository at this point in the history
…e code view lines does not dynamically adjust #1206

Issue: #1206
  • Loading branch information
xdan committed Jan 19, 2025
1 parent 8362b3b commit 01b7b74
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 9 deletions.
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,39 @@
> - :house: [Internal]
> - :nail_care: [Polish]

## 4.2.48

### :bug: Bug Fix

- [Source code mode: When the text area is resized, the number of visible code view lines does not dynamically adjust #1206](https://github.com/xdan/jodit/issues/1206)

#### :house: Internal

- Use typings for `options` in `Jodti.make(element, options)` method

Before:

```typescript
class Jodit {
static make(element: HTMLElement | string, options?: object): Jodit {
//...
}
}
```

After:

```typescript
class Jodit {
static make(
element: HTMLElement | string,
options?: DeepPartial<Config>
): Jodit {
//...
}
}
```

## 4.2.45

- Fixed bug with RTL mode when all dialogs were opened without RTL mode
Expand Down
7 changes: 5 additions & 2 deletions public/stand.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ <h1>Jodit Test Document</h1>
// const editor = Jodit.make('root.getElementById('edit')', {
const editor = Jodit.make('#editorNative', {
toolbarInlineForSelection: true,
"allowResizeX": true,
"height": 150,
"width": 500,
commandToHotkeys: {
someCustomCommand: 'shift+space'
},
Expand All @@ -62,8 +65,8 @@ <h1>Jodit Test Document</h1>
alert(111);
}
},
direction: 'rtl',
tabIndex: 0,
// direction: 'rtl',
// tabIndex: 0,
// shadowRoot: root,
// safeMode: true,
// disablePlugins: ['clean-html'],
Expand Down
28 changes: 25 additions & 3 deletions src/plugins/size/size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export class size extends Plugin {
* Manually change height
*/
private __setHeight(height: number | string): void {
const { clientHeight, clientWidth } = this.j.container;

if (isNumber(height)) {
const { minHeight, maxHeight } = this.j.o;

Expand All @@ -107,13 +109,15 @@ export class size extends Plugin {
this.j.storage.set('height', height);
}

this.__resizeWorkspaceImd();
this.__resizeWorkspaceImd({ clientHeight, clientWidth });
}

/**
* Manually change width
*/
private __setWidth(width: number | string): void {
const { clientHeight, clientWidth } = this.j.container;

if (isNumber(width)) {
const { minWidth, maxWidth } = this.j.o;

Expand All @@ -128,7 +132,7 @@ export class size extends Plugin {

css(this.j.container, 'width', width);

this.__resizeWorkspaceImd();
this.__resizeWorkspaceImd({ clientHeight, clientWidth });
}

/**
Expand All @@ -146,7 +150,15 @@ export class size extends Plugin {
* Calculate workspace height
*/
@autobind
private __resizeWorkspaceImd(): void {
private __resizeWorkspaceImd(
{
clientHeight,
clientWidth
}: {
clientHeight: number;
clientWidth: number;
} = this.j.container
): void {
if (!this.j || this.j.isDestructed || !this.j.o || this.j.o.inline) {
return;
}
Expand Down Expand Up @@ -186,6 +198,16 @@ export class size extends Plugin {
: 'auto'
);
}

const { clientHeight: newClientHeight, clientWidth: newClientWidth } =
this.j.container as HTMLElement;

if (
clientHeight !== newClientHeight ||
clientWidth !== newClientWidth
) {
this.j.e.fire(this.j, 'resize');
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/source/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Config.prototype.sourceEditorNativeOptions = {
};

Config.prototype.sourceEditorCDNUrlsJS = [
'https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.2/ace.js'
'https://cdnjs.cloudflare.com/ajax/libs/ace/1.37.1/ace.js'
];

Config.prototype.beautifyHTMLCDNUrlsJS = [
Expand Down
15 changes: 12 additions & 3 deletions src/plugins/source/editor/engines/ace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,16 @@ export class AceEditor
this.setValue(this.getValue());
}

const onResize = this.j.async.debounce(() => {
if (editor.isInDestruct) {
const onResize = this.j.async.throttle(() => {
if (
editor.isInDestruct ||
editor.getMode() === constants.MODE_WYSIWYG
) {
return;
}

const hasFocus = this.instance.isFocused();

if (editor.o.height !== 'auto') {
this.instance.setOption(
'maxLines',
Expand All @@ -169,9 +174,12 @@ export class AceEditor
}

this.instance.resize();
hasFocus && this.focus();
}, this.j.defaultTimeout * 2);

editor.e.on('afterResize afterSetMode', onResize);
editor.e
.on(editor, 'resize', onResize)
.on('afterResize afterSetMode', onResize);

onResize();

Expand Down Expand Up @@ -240,6 +248,7 @@ export class AceEditor
}

focus(): void {
this.instance.container.focus();
this.instance.focus();
}

Expand Down

0 comments on commit 01b7b74

Please sign in to comment.