Skip to content

Commit

Permalink
Fix double scrolling editor
Browse files Browse the repository at this point in the history
  • Loading branch information
tddang-linagora committed Nov 18, 2024
1 parent 3274d7f commit e0b57fc
Showing 1 changed file with 31 additions and 61 deletions.
92 changes: 31 additions & 61 deletions lib/src/widgets/html_editor_widget_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ class _HtmlEditorWidgetWebState extends State<HtmlEditorWidget> {
/// The view ID for the IFrameElement. Must be unique.
late String createdViewId;

/// The actual height of the editor, used to automatically set the height
late double actualHeight;

/// A Future that is observed by the [FutureBuilder]. We don't use a function
/// as the Future on the [FutureBuilder] because when the widget is rebuilt,
/// the function may be excessively called, hurting performance.
Expand All @@ -71,7 +68,6 @@ class _HtmlEditorWidgetWebState extends State<HtmlEditorWidget> {

@override
void initState() {
actualHeight = widget.otherOptions.height;
createdViewId = getRandString(10);
widget.controller.viewId = createdViewId;
initSummernote();
Expand Down Expand Up @@ -250,7 +246,6 @@ class _HtmlEditorWidgetWebState extends State<HtmlEditorWidget> {
\$('#summernote-2').summernote({
placeholder: "${widget.htmlEditorOptions.hint}",
tabsize: 2,
height: ${widget.otherOptions.height},
disableResizeEditor: false,
disableDragAndDrop: ${widget.htmlEditorOptions.disableDragAndDrop},
disableGrammar: false,
Expand Down Expand Up @@ -617,9 +612,6 @@ class _HtmlEditorWidgetWebState extends State<HtmlEditorWidget> {
}
final iframe = html.IFrameElement()
..width = maxWidth
..height = widget.htmlEditorOptions.autoAdjustHeight
? actualHeight.toString()
: widget.otherOptions.height.toString()
// ignore: unsafe_html, necessary to load HTML string
..srcdoc = htmlString
..style.border = 'none'
Expand All @@ -635,45 +627,37 @@ class _HtmlEditorWidgetWebState extends State<HtmlEditorWidget> {

@override
Widget build(BuildContext context) {
final child = SizedBox(
height: widget.htmlEditorOptions.autoAdjustHeight
? actualHeight
: widget.otherOptions.height,
child: Column(
children: <Widget>[
widget.htmlToolbarOptions.toolbarPosition == ToolbarPosition.aboveEditor
? ToolbarWidget(
key: toolbarKey,
controller: widget.controller,
htmlToolbarOptions: widget.htmlToolbarOptions,
callbacks: widget.callbacks)
: const SizedBox(height: 0, width: 0),
Expanded(
child: Directionality(
textDirection: TextDirection.ltr,
child: FutureBuilder<bool>(
future: summernoteInit,
builder: (context, snapshot) {
if (snapshot.hasData) {
return HtmlElementView(
viewType: createdViewId,
);
} else {
return Container(
height: widget.htmlEditorOptions.autoAdjustHeight
? actualHeight
: widget.otherOptions.height);
}
}))),
widget.htmlToolbarOptions.toolbarPosition == ToolbarPosition.belowEditor
? ToolbarWidget(
key: toolbarKey,
controller: widget.controller,
htmlToolbarOptions: widget.htmlToolbarOptions,
callbacks: widget.callbacks)
: const SizedBox(height: 0, width: 0),
],
),
final child = Column(
children: <Widget>[
widget.htmlToolbarOptions.toolbarPosition == ToolbarPosition.aboveEditor
? ToolbarWidget(
key: toolbarKey,
controller: widget.controller,
htmlToolbarOptions: widget.htmlToolbarOptions,
callbacks: widget.callbacks)
: const SizedBox(height: 0, width: 0),
Expanded(
child: Directionality(
textDirection: TextDirection.ltr,
child: FutureBuilder<bool>(
future: summernoteInit,
builder: (context, snapshot) {
if (snapshot.hasData) {
return HtmlElementView(
viewType: createdViewId,
);
} else {
return const SizedBox.shrink();
}
}))),
widget.htmlToolbarOptions.toolbarPosition == ToolbarPosition.belowEditor
? ToolbarWidget(
key: toolbarKey,
controller: widget.controller,
htmlToolbarOptions: widget.htmlToolbarOptions,
callbacks: widget.callbacks)
: const SizedBox(height: 0, width: 0),
],
);

return Focus(
Expand Down Expand Up @@ -922,20 +906,6 @@ class _HtmlEditorWidgetWebState extends State<HtmlEditorWidget> {
var jsonStr2 = _jsonEncoder.convert(data2);
_summernoteOnLoadListener = html.window.onMessage.listen((event) {
var data = json.decode(event.data);
if (data['type'] != null &&
data['type'].contains('toDart: htmlHeight') &&
data['view'] == createdViewId &&
widget.htmlEditorOptions.autoAdjustHeight) {
final docHeight = data['height'] ?? actualHeight;
if ((docHeight != null && docHeight != actualHeight) &&
mounted &&
docHeight > 0) {
setState(mounted, this.setState, () {
actualHeight =
docHeight + (toolbarKey.currentContext?.size?.height ?? 0);
});
}
}
if (data['type'] != null &&
data['type'].contains('toDart: onChangeContent') &&
data['view'] == createdViewId) {
Expand Down

0 comments on commit e0b57fc

Please sign in to comment.