Skip to content

Commit b938548

Browse files
committed
fix: can not fold ruby & sql
1 parent d551952 commit b938548

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/main.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import 'codemirror/addon/fold/foldgutter.css'
22
import { Plugin, decorate, path } from '@typora-community-plugin/core'
33
import { editor } from 'typora'
4+
import type * as CodeMirror from 'codemirror'
45

56

7+
const FOLD_BY_INDENT = ['ruby', 'sql']
8+
69
export default class extends Plugin {
710

11+
private _isModeFixed = false
12+
813
onload() {
14+
915
this.registerScript('./addon/fold/foldcode.js')
1016
this.registerScript('./addon/fold/foldgutter.js')
1117
this.registerScript('./addon/fold/brace-fold.js')
@@ -16,6 +22,19 @@ export default class extends Plugin {
1622

1723
this.register(
1824
decorate.returnValue(editor.fences, 'addCodeBlock', (_, cm) => {
25+
if (!this._isModeFixed) {
26+
for (const lang of FOLD_BY_INDENT) {
27+
this.register(
28+
// @ts-ignore
29+
decorate.returnValue(CodeMirror.modes, lang, (_, results) => {
30+
// @ts-ignore
31+
results.fold = 'indent'
32+
return results
33+
}))
34+
}
35+
this._isModeFixed = true
36+
}
37+
1938
const gutters = cm.getOption('gutters') ?? []
2039
// @ts-ignore
2140
cm.setOption('foldGutter', true)

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "plylrnsdy",
66
"authorUrl": "https://github.com/plylrnsdy",
77
"repo": "typora-community-plugin/typora-plugin-code-folding",
8-
"version": "1.0.0",
8+
"version": "1.0.2",
99
"minAppVersion": "1.5.0",
1010
"minCoreVersion": "2.0.0-beta.36",
1111
"platforms": ["win32", "linux", "darwin"]

test/vault/doc2.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,42 @@
11
# doc2
22

33
```javascript
4+
// JavaScript
45
function add(a, b) {
56
if (typeof a !== 'number' || typeof b !== 'number') {
67
throw new TypeError()
78
}
89
return a + b
910
}
1011
```
12+
13+
```sql
14+
-- SQL
15+
SELECT a, b, c
16+
FROM table1
17+
WHERE id = 1
18+
```
19+
20+
```ruby
21+
# Ruby
22+
class ImportMap::Commands < Thor
23+
include Thor.Actions
24+
25+
def pin(*)
26+
package.download(package, url)
27+
end
28+
29+
private
30+
31+
def packager
32+
@package ||= Importer.Packager.new
33+
end
34+
end
35+
```
36+
37+
```python
38+
# Python
39+
def add(a, b):
40+
return a + b
41+
```
42+

0 commit comments

Comments
 (0)