Skip to content

Commit e5c09cc

Browse files
authored
Editor max height i177 (#180)
* Add editor-max-height to prevent maximum growth * Add doc entry and test * Add release note * Version bump
1 parent 6229863 commit e5c09cc

6 files changed

+63
-6
lines changed

_extensions/webr/_extension.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: webr
22
title: Embedded webr code cells
33
author: James Joseph Balamuta
4-
version: 0.4.2-dev.1
4+
version: 0.4.2-dev.2
55
quarto-required: ">=1.2.198"
66
contributes:
77
filters:

_extensions/webr/qwebr-monaco-editor-element.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,18 @@ globalThis.qwebrCreateMonacoEditorInstance = function (cellData) {
5656
// Dynamically modify the height of the editor window if new lines are added.
5757
let ignoreEvent = false;
5858
const updateHeight = () => {
59-
const contentHeight = editor.getContentHeight();
59+
// Increment editor height by 2 to prevent vertical scroll bar from appearing
60+
const contentHeight = editor.getContentHeight() + 2;
61+
62+
// Retrieve editor-max-height option
63+
const maxEditorHeight = qwebrOptions['editor-max-height'];
64+
65+
// If editor-max-height is missing, allow infinite growth. Otherwise, threshold.
66+
const editorHeight = !maxEditorHeight ? contentHeight : Math.min(contentHeight, maxEditorHeight);
67+
6068
// We're avoiding a width change
6169
//editorDiv.style.width = `${width}px`;
62-
editorDiv.style.height = `${contentHeight}px`;
70+
editorDiv.style.height = `${editorHeight}px`;
6371
try {
6472
ignoreEvent = true;
6573

_extensions/webr/webr.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ local qwebRDefaultCellOptions = {
7272
["fig-width"] = 7,
7373
["fig-height"] = 5,
7474
["out-width"] = "700px",
75-
["out-height"] = ""
75+
["out-height"] = "",
76+
["editor-max-height"] = ""
7677
}
7778

7879
----

docs/qwebr-cell-options.qmd

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ The `{quarto-webr}` extension does not support all of the cell options from [Qua
3838
| `context` | `interactive` | Describe how the cell should operate on the page through either `interactive` (Runnable code editor), `output` (Output only of executed at runtime), or `setup` (execute code without seeing output at runtime). |
3939
| `autorun` | `false` | Allow `interactive` cells to be run during document initialization without a user pressing run code. |
4040
| `read-only` | `false` | Prevent code in `interactive` cells from being modified by disallowing code input. |
41+
| `editor-max-height` | `0` | Set a threshold to prevent infinite growth of the editor window. |
4142

4243

4344
:::{.callout-note}
44-
Options listed here are unique to the `{quarto-webr}` extension. For more details, please see [Hiding and Executing Code](qwebr-internal-cell.qmd).
45+
Options listed here are unique to the `{quarto-webr}` extension. For details regarding `context`, please see [Hiding and Executing Code](qwebr-internal-cell.qmd).
4546
:::
4647

4748
## Attributes

docs/qwebr-release-notes.qmd

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ format:
88
toc: true
99
---
1010

11-
# 0.4.2-dev.1: ??????? (??-??-??)
11+
# 0.4.2-dev.2: ??????? (??-??-??)
1212

1313
:::{.callout-note}
1414
Features listed under the `-dev` version have not yet been solidified and may change at any point.
@@ -18,8 +18,13 @@ Features listed under the `-dev` version have not yet been solidified and may ch
1818

1919
- Added `cell-options` document-level option to specify global defaults for `{webr-r}` options ([#173](https://github.com/coatless/quarto-webr/pulls/173), thanks [ute](https://github.com/ute)!)
2020

21+
- Added `editor-max-height` cell option to limit growth of the editor window. ([#177](https://github.com/coatless/quarto-webr/pulls/173), thanks [ute](https://github.com/ute)!)
22+
23+
2124
## Bug fixes
2225

26+
- Prevented vertical scroll bars from always being present by modifying the adaptive container of the editor to always be at least 2 pixels greater than the editor's content instead of being the exact amount. ([#164](https://github.com/coatless/quarto-webr/issues/164))
27+
2328
## Documentation
2429

2530
# 0.4.1: Vivid Montage (03-25-2024)

tests/qwebr-test-editor-options.qmd

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: "Test: Editor Options"
3+
format: html
4+
engine: knitr
5+
filters:
6+
- webr
7+
---
8+
9+
Check that the editor responses correctly to options being set.
10+
11+
## Interactive
12+
13+
14+
### Single line
15+
16+
```{webr-r}
17+
print("test")
18+
```
19+
20+
21+
### Uncapped height
22+
23+
24+
```{webr-r}
25+
print("test")
26+
59120
27+
1 + 1
28+
c(1, 3, 4)
29+
print("line 5")
30+
```
31+
32+
33+
### Height cap
34+
35+
```{webr-r}
36+
#| editor-max-height: 80
37+
print("test")
38+
59120
39+
1 + 1
40+
c(1, 3, 4)
41+
print("line 5")
42+
```

0 commit comments

Comments
 (0)