From 5e371dcbd252bfb04108b10f20c61569c72a0e47 Mon Sep 17 00:00:00 2001 From: Renyuan Wang Date: Tue, 19 Sep 2023 19:04:30 +1200 Subject: [PATCH] Support line height --- example/index.js | 28 ++++++++++++++++++++++++++++ package.json | 2 +- src/ace.tsx | 15 +++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/example/index.js b/example/index.js index e176ec6c4..3909a9776 100644 --- a/example/index.js +++ b/example/index.js @@ -98,6 +98,11 @@ class App extends Component { fontSize: parseInt(e.target.value, 10) }); } + setLineHeight(e) { + this.setState({ + lineHeight: parseInt(e.target.value, 10) + }); + } constructor(props) { super(props); this.state = { @@ -108,6 +113,7 @@ class App extends Component { enableBasicAutocompletion: false, enableLiveAutocompletion: false, fontSize: 14, + lineHeight: 19, showGutter: true, showPrintMargin: true, highlightActiveLine: true, @@ -119,6 +125,7 @@ class App extends Component { this.setMode = this.setMode.bind(this); this.onChange = this.onChange.bind(this); this.setFontSize = this.setFontSize.bind(this); + this.setLineHeight = this.setLineHeight.bind(this), this.setBoolean = this.setBoolean.bind(this); } render() { @@ -182,6 +189,25 @@ class App extends Component {

+
+ +

+ + + +

+
+

@@ -312,6 +338,7 @@ class App extends Component { onCursorChange={this.onCursorChange} onValidate={this.onValidate} value={this.state.value} + lineHeight={this.state.lineHeight} fontSize={this.state.fontSize} showPrintMargin={this.state.showPrintMargin} showGutter={this.state.showGutter} @@ -340,6 +367,7 @@ class App extends Component { onLoad={this.onLoad} onChange={this.onChange} fontSize={${this.state.fontSize}} + lineHeight={${this.state.lineHeight}} showPrintMargin={${this.state.showPrintMargin}} showGutter={${this.state.showGutter}} highlightActiveLine={${this.state.highlightActiveLine}} diff --git a/package.json b/package.json index dfe1b7ddb..926711dad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-ace", - "version": "10.1.0", + "version": "10.1.1", "description": "A react component for Ace Editor", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/ace.tsx b/src/ace.tsx index fe294aae9..5ff2cb77a 100644 --- a/src/ace.tsx +++ b/src/ace.tsx @@ -33,6 +33,7 @@ export interface IAceEditorProps { width?: string; className?: string; fontSize?: number | string; + lineHeight?: number | string; showGutter?: boolean; showPrintMargin?: boolean; highlightActiveLine?: boolean; @@ -83,6 +84,7 @@ export default class ReactAce extends React.Component { height: PropTypes.string, width: PropTypes.string, fontSize: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + lineHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), showGutter: PropTypes.bool, onChange: PropTypes.func, onCopy: PropTypes.func, @@ -189,6 +191,7 @@ export default class ReactAce extends React.Component { focus, theme, fontSize, + lineHeight, value, defaultValue, showGutter, @@ -238,6 +241,10 @@ export default class ReactAce extends React.Component { this.editor.setFontSize( typeof fontSize === "number" ? `${fontSize}px` : fontSize ); + if (lineHeight) { + this.editor.container.style.lineHeight = typeof lineHeight === "number" ? `${lineHeight}px` : `${lineHeight}` + this.editor.renderer.updateFontSize() + } this.editor .getSession() .setValue(!defaultValue ? value || "" : defaultValue); @@ -388,6 +395,14 @@ export default class ReactAce extends React.Component { : nextProps.fontSize ); } + if (nextProps.lineHeight !== oldProps.lineHeight) { + this.editor.container.style.lineHeight = + typeof nextProps.lineHeight === "number" + ? `${nextProps.lineHeight}px` + : nextProps.lineHeight + ; + this.editor.renderer.updateFontSize() + } if (nextProps.wrapEnabled !== oldProps.wrapEnabled) { this.editor.getSession().setUseWrapMode(nextProps.wrapEnabled); }