|
1 | 1 | "use strict" |
2 | 2 |
|
3 | | -import { Emitter, CompositeDisposable } from "atom" |
| 3 | +import { Emitter, CompositeDisposable, Disposable } from "atom" |
| 4 | +import Decoration from "./decoration" |
4 | 5 | import StableAdapter from "./adapters/stable-adapter" |
5 | 6 | import { editorsMinimaps } from "./main" |
6 | 7 |
|
7 | 8 | let nextModelId = 1 |
8 | 9 |
|
| 10 | +// returned in the decorations API when minimap is destoryed |
| 11 | +const disposedDisposable = new Disposable() |
| 12 | +disposedDisposable.dispose() |
| 13 | +const markerMock = { |
| 14 | + onDidDestroy: () => disposedDisposable, |
| 15 | + getScreenRange: () => new Range(), |
| 16 | +} |
| 17 | +const dummyDecoration = new Decoration(markerMock, null, {}) |
| 18 | + |
9 | 19 | /** |
10 | 20 | * The Minimap class is the underlying model of a <MinimapElement>. |
11 | 21 | * Most manipulations of the minimap is done through the model. |
@@ -1108,60 +1118,52 @@ export default class Minimap { |
1108 | 1118 |
|
1109 | 1119 | /** |
1110 | 1120 | * get the DecorationManagement API for the current minimapElement |
1111 | | - * @return {DecorationManagement} |
| 1121 | + * @return {DecorationManagement | undefined} |
1112 | 1122 | */ |
1113 | 1123 | getDecorationManagement() { |
1114 | 1124 | if (!this.DecorationManagement) { |
1115 | | - if (this.minimapElement) { |
| 1125 | + if (this.minimapElement?.DecorationManagement) { |
1116 | 1126 | this.DecorationManagement = this.minimapElement.DecorationManagement |
1117 | | - } else { |
1118 | | - // TODO: find why this becomes null: https://github.com/atom-minimap/minimap/issues/766 |
1119 | | - throw new Error(`getDecorationManagement failed. |
1120 | | - this.DecorationManagement: ${JSON.stringify(this.DecorationManagement)} |
1121 | | - this.minimapElement: ${JSON.stringify(this.minimapElement)} |
1122 | | - this.textEditor: ${this.getTextEditor()} |
1123 | | - this: ${JSON.stringify(this)} |
1124 | | - `) |
1125 | 1127 | } |
1126 | 1128 | } |
1127 | 1129 | return this.DecorationManagement |
1128 | 1130 | } |
1129 | 1131 |
|
1130 | 1132 | // Decoration API duplicated for backward compatibility in the service |
1131 | 1133 | getDecorations() { |
1132 | | - return this.getDecorationManagement().getDecorations() |
| 1134 | + return this.getDecorationManagement()?.getDecorations() ?? [] |
1133 | 1135 | } |
1134 | 1136 | onDidAddDecoration(...args) { |
1135 | | - return this.getDecorationManagement().onDidAddDecoration(...args) |
| 1137 | + return this.getDecorationManagement()?.onDidAddDecoration(...args) ?? disposedDisposable |
1136 | 1138 | } |
1137 | 1139 | onDidRemoveDecoration(...args) { |
1138 | | - return this.getDecorationManagement().onDidRemoveDecoration(...args) |
| 1140 | + return this.getDecorationManagement()?.onDidRemoveDecoration(...args) ?? disposedDisposable |
1139 | 1141 | } |
1140 | 1142 | onDidChangeDecorationRange(...args) { |
1141 | | - return this.getDecorationManagement().onDidChangeDecorationRange(...args) |
| 1143 | + return this.getDecorationManagement()?.onDidChangeDecorationRange(...args) ?? disposedDisposable |
1142 | 1144 | } |
1143 | 1145 | onDidUpdateDecoration(...args) { |
1144 | | - return this.getDecorationManagement().onDidUpdateDecoration(...args) |
| 1146 | + return this.getDecorationManagement()?.onDidUpdateDecoration(...args) ?? disposedDisposable |
1145 | 1147 | } |
1146 | 1148 | decorationForId(...args) { |
1147 | | - return this.getDecorationManagement().decorationForId(...args) |
| 1149 | + return this.getDecorationManagement()?.decorationForId(...args) ?? dummyDecoration |
1148 | 1150 | } |
1149 | 1151 | decorationsForScreenRowRange(...args) { |
1150 | | - return this.getDecorationManagement().decorationsForScreenRowRange(...args) |
| 1152 | + return this.getDecorationManagement()?.decorationsForScreenRowRange(...args) ?? dummyDecoration |
1151 | 1153 | } |
1152 | 1154 | decorationsByTypeThenRows() { |
1153 | | - return this.getDecorationManagement().decorationsByTypeThenRows() |
| 1155 | + return this.getDecorationManagement()?.decorationsByTypeThenRows() ?? dummyDecoration |
1154 | 1156 | } |
1155 | 1157 | decorateMarker(...args) { |
1156 | | - return this.getDecorationManagement().decorateMarker(...args) |
| 1158 | + return this.getDecorationManagement()?.decorateMarker(...args) ?? dummyDecoration |
1157 | 1159 | } |
1158 | 1160 | removeDecoration(...args) { |
1159 | | - return this.getDecorationManagement().removeDecoration(...args) |
| 1161 | + return this.getDecorationManagement()?.removeDecoration(...args) |
1160 | 1162 | } |
1161 | 1163 | removeAllDecorationsForMarker(...args) { |
1162 | | - return this.getDecorationManagement().removeAllDecorationsForMarker(...args) |
| 1164 | + return this.getDecorationManagement()?.removeAllDecorationsForMarker(...args) |
1163 | 1165 | } |
1164 | 1166 | removeAllDecorations() { |
1165 | | - return this.getDecorationManagement().removeAllDecorations() |
| 1167 | + return this.getDecorationManagement()?.removeAllDecorations() |
1166 | 1168 | } |
1167 | 1169 | } |
0 commit comments