Skip to content

Commit

Permalink
feat: diff editor language
Browse files Browse the repository at this point in the history
  • Loading branch information
Saber2pr committed Mar 13, 2022
1 parent dd7c175 commit e99d349
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -8,6 +8,8 @@ yarn add @saber2pr/monaco

### Usage

editor:

```tsx
import { createEditor } from '@saber2pr/monaco'

Expand All @@ -17,6 +19,7 @@ const editor = createEditor(
{
// file: file-content
'input.jsx': "const a = 'hello';",
'input.css': '#root { color: red; }',
},
{ theme: 'vs-dark' }
)
Expand All @@ -33,3 +36,12 @@ editor.changeModel('input.css')
// get modal
editor.getModel('input.jsx').onDidChangeContent
```

diffEditor:

```tsx
import { createEditor } from '@saber2pr/monaco'

// container, oldText, newText, language
createDiffEditor(dom, '{"name": "app"}', '{"name": "subApp"}', 'json')
```
7 changes: 4 additions & 3 deletions src/core/createDiffEditor.ts
Expand Up @@ -10,10 +10,11 @@ import { monaco } from './monaco'
export const createDiffEditor = (
container: HTMLElement,
original: string,
modified: string
modified: string,
language: string = 'text/plain'
) => {
const originalModel = monaco.editor.createModel(original, 'text/plain')
const modifiedModel = monaco.editor.createModel(modified, 'text/plain')
const originalModel = monaco.editor.createModel(original, language)
const modifiedModel = monaco.editor.createModel(modified, language)

originalModel.updateOptions(commonOptions)
modifiedModel.updateOptions(commonOptions)
Expand Down

0 comments on commit e99d349

Please sign in to comment.