-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Higher fidelity resizing of CodeMirror instances when UI changes shape
- Loading branch information
Showing
4 changed files
with
59 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the | ||
* LICENSE-examples file in the root directory of this source tree. | ||
*/ | ||
|
||
import ReactDOM from 'react-dom'; | ||
|
||
|
||
/** | ||
* When a containing DOM node's height has been altered, trigger a resize of | ||
* the related CodeMirror instance so that it is always correctly sized. | ||
*/ | ||
export default class CodeMirrorSizer { | ||
constructor() { | ||
this.sizes = []; | ||
} | ||
|
||
updateSizes(components) { | ||
components.forEach((component, i) => { | ||
const size = ReactDOM.findDOMNode(component).clientHeight; | ||
if (i <= this.sizes.length && size !== this.sizes[i]) { | ||
component.getCodeMirror().setSize(); | ||
} | ||
this.sizes[i] = size; | ||
}); | ||
} | ||
} |