Skip to content

Commit fb0258f

Browse files
committed
Fix scrollbars across themes
Refactor code mirror load code
1 parent bdf7d5f commit fb0258f

File tree

4 files changed

+10
-39
lines changed

4 files changed

+10
-39
lines changed

src/lib/CodeMirror.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,16 @@ import 'codemirror/keymap/emacs'
1717
import 'codemirror/keymap/vim'
1818
import 'codemirror-abap'
1919
import { loadMode } from '../shared/lib/codemirror/util'
20-
import debounce from 'lodash/debounce'
2120

2221
// Custom addons
2322
import { initHyperlink } from './addons/hyperlink'
2423

25-
const dispatchModeLoad = debounce(() => {
26-
window.dispatchEvent(new CustomEvent('codemirror-mode-load'))
27-
}, 300)
28-
29-
export async function requireMode(mode: string) {
30-
try {
31-
await import(`codemirror/mode/${mode}/${mode}.js`)
32-
dispatchModeLoad()
33-
} catch (error) {
34-
console.warn(error)
35-
}
36-
}
37-
3824
export function getCodeMirrorTheme(theme?: string) {
3925
if (theme == null) return 'default'
4026
if (theme === 'solarized-dark') return 'solarized dark'
4127
return theme
4228
}
4329

44-
function loadMode(_CodeMirror: any) {
45-
const memoizedModeResult = new Map<string, CodeMirror.ModeInfo | null>()
46-
function findModeByMIME(mime: string) {
47-
let result = memoizedModeResult.get(mime)
48-
if (result === undefined) {
49-
result = CodeMirror.findModeByMIME(mime) || null
50-
memoizedModeResult.set(mime, result)
51-
}
52-
return result
53-
}
54-
55-
const originalGetMode = CodeMirror.getMode
56-
_CodeMirror.getMode = (config: CodeMirror.EditorConfiguration, mime: any) => {
57-
const modeObj = originalGetMode(config, mime)
58-
if (modeObj.name === 'null' && typeof mime === 'string') {
59-
const mode = findModeByMIME(mime)
60-
if (mode != null) {
61-
requireMode(mode.mode)
62-
}
63-
}
64-
return modeObj
65-
}
66-
}
67-
6830
// Initialize custom addons
6931
initHyperlink(CodeMirror)
7032
loadMode(CodeMirror)

src/shared/components/atoms/GlobalStyle.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export default createGlobalStyle<BaseTheme>`
148148
149149
/* scrollbar itself */
150150
::-webkit-scrollbar-thumb {
151-
background-color: ${({ theme }) => theme.colors.background.quaternary};
151+
background-color: ${({ theme }) => theme.scroll.background};
152152
}
153153
154154
/* set button(top and bottom of the scrollbar) */
@@ -192,6 +192,7 @@ export default createGlobalStyle<BaseTheme>`
192192
bottom: 15px;
193193
right: 15px;
194194
}
195+
195196
#nprogress .spinner-icon {
196197
width: 18px;
197198
height: 18px;
@@ -203,14 +204,17 @@ export default createGlobalStyle<BaseTheme>`
203204
-webkit-animation: nprogress-spinner 400ms linear infinite;
204205
animation: nprogress-spinner 400ms linear infinite;
205206
}
207+
206208
.nprogress-custom-parent {
207209
overflow: hidden;
208210
position: relative;
209211
}
212+
210213
.nprogress-custom-parent #nprogress .spinner,
211214
.nprogress-custom-parent #nprogress .bar {
212215
position: absolute;
213216
}
217+
214218
@-webkit-keyframes nprogress-spinner {
215219
0% {
216220
-webkit-transform: rotate(0deg);
@@ -219,6 +223,7 @@ export default createGlobalStyle<BaseTheme>`
219223
-webkit-transform: rotate(360deg);
220224
}
221225
}
226+
222227
@keyframes nprogress-spinner {
223228
0% {
224229
transform: rotate(0deg);

src/shared/lib/styled/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const commonTheme: SharedTheme = {
4040
codeEditorSelectedTextBackgroundColor: '#ffc107',
4141
sidebarSearchHighlightTextColor: '#E6E6E6',
4242
sidebarSearchHighlightBackgroundColor: '#6a320f',
43+
scroll: { background: '#888' },
4344
}
4445

4546
export default commonTheme

src/shared/lib/styled/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export interface SharedTheme {
4545
codeEditorSelectedTextBackgroundColor: string
4646
sidebarSearchHighlightTextColor: string
4747
sidebarSearchHighlightBackgroundColor: string
48+
scroll: {
49+
background: string
50+
}
4851
}
4952

5053
/** background color gradient => starting from main color, fade more and more towards the opposite BW ***/

0 commit comments

Comments
 (0)