diff options
author | angelozerr | 2018-02-25 05:21:35 +0000 |
---|---|---|
committer | Mickael Istria | 2018-03-01 21:25:37 +0000 |
commit | a8dcd5187f8a0d9d39ee455a2e49300cfa0b5566 (patch) | |
tree | 78ae45b14b687bf2d233b88b4f66bdae120b6402 | |
parent | 272bf0d8ebce8f12e9bb0de2c389d3a18d319afb (diff) | |
download | eclipse.platform.swt-a8dcd5187f8a0d9d39ee455a2e49300cfa0b5566.tar.gz eclipse.platform.swt-a8dcd5187f8a0d9d39ee455a2e49300cfa0b5566.tar.xz eclipse.platform.swt-a8dcd5187f8a0d9d39ee455a2e49300cfa0b5566.zip |
Bug 531639 - [StyledText] Improve performance on load when
setLineSpacingProvider is called
Change-Id: Ie26e1718b9af2cc5e008c53a4db2012684713777
Signed-off-by: angelozerr <angelo.zerr@gmail.com>
2 files changed, 27 insertions, 3 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java index 954e6e54b3..a05e0bf0a1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java @@ -9381,8 +9381,32 @@ public void setLineSpacingProvider(StyledTextLineSpacingProvider lineSpacingProv && renderer.getLineSpacingProvider().equals(lineSpacingProvider))) return; renderer.setLineSpacingProvider(lineSpacingProvider); - setVariableLineHeight(); - resetCache(0, content.getLineCount()); + // reset lines cache if needed + if (lineSpacingProvider == null) { + if (!isFixedLineHeight()) { + resetCache(0, content.getLineCount()); + } + } else { + if (isFixedLineHeight()) { + int firstLine = -1; + for (int i = 0; i < content.getLineCount(); i++) { + Integer lineSpacing = lineSpacingProvider.getLineSpacing(i); + if (lineSpacing != null && lineSpacing > 0) { + // there is a custom line spacing, set StyledText as variable line height mode + setVariableLineHeight(); + // reset only the line size + renderer.reset(i, 1); + if (firstLine == -1) { + firstLine = i; + } + } + } + if (firstLine != -1) { + // call reset cache for the first line which have changed to recompute scrollbars + resetCache(firstLine, 0); + } + } + } setCaretLocation(); super.redraw(); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java index 7963e3308c..d8144511b3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java @@ -889,7 +889,7 @@ TextLayout getTextLayout(int lineIndex) { * resetCache, setCaretLocation, redraw methods only at the end of the compute of all lines spacing. */ lineSpacingComputing = true; - styledText.resetCache(lineIndex, styledText.getLineCount()); + styledText.resetCache(lineIndex, 1); styledText.setVariableLineHeight(); styledText.setCaretLocation(); styledText.redraw(); |