Skip to content

Commit

Permalink
Merge pull request #161 from gaelj/release
Browse files Browse the repository at this point in the history
Release 0.7.5
  • Loading branch information
gaelj authored Mar 3, 2024
2 parents 2b78c9d + 6c0c2d8 commit 1cc3763
Show file tree
Hide file tree
Showing 13 changed files with 371 additions and 513 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## 0.7.5 - 2024-03-03

### 🎨 Improve structure / format of the code

- Minor cleanup
- Use integrated support for multiple cursors

### ⬆️ Upgrade dependencies

- Update js dependencies

### 🚨 Fix compiler / linter warnings

- Fix warning in example project Upload endpoint

## 0.7.4 - 2024-03-01

### ✨ Introduce new features
Expand Down
2 changes: 1 addition & 1 deletion CodeMirror6/CodeMirror6.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AssemblyName>GaelJ.BlazorCodeMirror6</AssemblyName>
<IsPackable>true</IsPackable>
<PackageId>GaelJ.BlazorCodeMirror6</PackageId>
<Version>0.7.4</Version>
<Version>0.7.5</Version>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
594 changes: 297 additions & 297 deletions CodeMirror6/NodeLib/package-lock.json

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions CodeMirror6/NodeLib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "Gaël James",
"license": "MIT",
"dependencies": {
"@codemirror/autocomplete": "^6.12.0",
"@codemirror/autocomplete": "^6.13.0",
"@codemirror/lang-cpp": "^6.0.2",
"@codemirror/lang-css": "^6.2.1",
"@codemirror/lang-html": "^6.4.8",
Expand All @@ -23,52 +23,52 @@
"@codemirror/lang-python": "^6.1.4",
"@codemirror/lang-rust": "^6.0.1",
"@codemirror/lang-sass": "^6.0.2",
"@codemirror/lang-sql": "^6.5.5",
"@codemirror/lang-sql": "^6.6.0",
"@codemirror/lang-xml": "^6.0.2",
"@codemirror/language-data": "^6.4.1",
"@codemirror/lint": "^6.5.0",
"@codemirror/merge": "^6.6.0",
"@codemirror/theme-one-dark": "^6.1.2",
"@microsoft/dotnet-js-interop": "^8.0.0",
"@replit/codemirror-indentation-markers": "^6.5.0",
"@uiw/codemirror-theme-abcdef": "^4.21.23",
"@uiw/codemirror-theme-abyss": "^4.21.23",
"@uiw/codemirror-theme-androidstudio": "^4.21.23",
"@uiw/codemirror-theme-andromeda": "^4.21.23",
"@uiw/codemirror-theme-atomone": "^4.21.23",
"@uiw/codemirror-theme-aura": "^4.21.23",
"@uiw/codemirror-theme-basic": "^4.21.23",
"@uiw/codemirror-theme-bbedit": "^4.21.23",
"@uiw/codemirror-theme-copilot": "^4.21.23",
"@uiw/codemirror-theme-darcula": "^4.21.23",
"@uiw/codemirror-theme-duotone": "^4.21.23",
"@uiw/codemirror-theme-eclipse": "^4.21.23",
"@uiw/codemirror-theme-github": "^4.21.23",
"@uiw/codemirror-theme-gruvbox-dark": "^4.21.23",
"@uiw/codemirror-theme-kimbie": "^4.21.23",
"@uiw/codemirror-theme-material": "^4.21.23",
"@uiw/codemirror-theme-monokai": "^4.21.23",
"@uiw/codemirror-theme-monokai-dimmed": "^4.21.23",
"@uiw/codemirror-theme-nord": "^4.21.23",
"@uiw/codemirror-theme-okaidia": "^4.21.23",
"@uiw/codemirror-theme-quietlight": "^4.21.23",
"@uiw/codemirror-theme-red": "^4.21.23",
"@uiw/codemirror-theme-solarized": "^4.21.23",
"@uiw/codemirror-theme-sublime": "^4.21.23",
"@uiw/codemirror-theme-tokyo-night": "^4.21.23",
"@uiw/codemirror-theme-tokyo-night-day": "^4.21.23",
"@uiw/codemirror-theme-tokyo-night-storm": "^4.21.23",
"@uiw/codemirror-theme-vscode": "^4.21.23",
"@uiw/codemirror-theme-white": "^4.21.23",
"@uiw/codemirror-theme-xcode": "^4.21.23",
"@uiw/codemirror-theme-abcdef": "^4.21.24",
"@uiw/codemirror-theme-abyss": "^4.21.24",
"@uiw/codemirror-theme-androidstudio": "^4.21.24",
"@uiw/codemirror-theme-andromeda": "^4.21.24",
"@uiw/codemirror-theme-atomone": "^4.21.24",
"@uiw/codemirror-theme-aura": "^4.21.24",
"@uiw/codemirror-theme-basic": "^4.21.24",
"@uiw/codemirror-theme-bbedit": "^4.21.24",
"@uiw/codemirror-theme-copilot": "^4.21.24",
"@uiw/codemirror-theme-darcula": "^4.21.24",
"@uiw/codemirror-theme-duotone": "^4.21.24",
"@uiw/codemirror-theme-eclipse": "^4.21.24",
"@uiw/codemirror-theme-github": "^4.21.24",
"@uiw/codemirror-theme-gruvbox-dark": "^4.21.24",
"@uiw/codemirror-theme-kimbie": "^4.21.24",
"@uiw/codemirror-theme-material": "^4.21.24",
"@uiw/codemirror-theme-monokai": "^4.21.24",
"@uiw/codemirror-theme-monokai-dimmed": "^4.21.24",
"@uiw/codemirror-theme-nord": "^4.21.24",
"@uiw/codemirror-theme-okaidia": "^4.21.24",
"@uiw/codemirror-theme-quietlight": "^4.21.24",
"@uiw/codemirror-theme-red": "^4.21.24",
"@uiw/codemirror-theme-solarized": "^4.21.24",
"@uiw/codemirror-theme-sublime": "^4.21.24",
"@uiw/codemirror-theme-tokyo-night": "^4.21.24",
"@uiw/codemirror-theme-tokyo-night-day": "^4.21.24",
"@uiw/codemirror-theme-tokyo-night-storm": "^4.21.24",
"@uiw/codemirror-theme-vscode": "^4.21.24",
"@uiw/codemirror-theme-white": "^4.21.24",
"@uiw/codemirror-theme-xcode": "^4.21.24",
"codemirror": "^6.0.1",
"codemirror-lang-mermaid": "^0.5.0",
"emojilib": "^3.0.11",
"node-emoji": "^2.1.3",
"thememirror": "^2.0.1"
},
"devDependencies": {
"@babel/runtime": "^7.23.9",
"@babel/runtime": "^7.24.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
Expand Down
10 changes: 5 additions & 5 deletions CodeMirror6/NodeLib/src/CmColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,17 @@ function insertTabulationAtEndOfDocumentIfSelectionAtEnd(view: EditorView) {
}

// extract first csv cell from a line of text. Ignore the separator if it is inside quotes. Ignore quotes if they are escaped by another quote. Return the extracted cell and the remaining text after the cell.
function extractNextCell(line: string, separator: string): string[] {
function extractNextCell(remaining: string, separator: string): string[] {
let cell = ""
let inQuotes = false
let escapeNext = false
let separatorFound = false
for (let i = 0; i < line.length; i++) {
const char = line[i]
for (let i = 0; i < remaining.length; i++) {
const char = remaining[i]
if (escapeNext) {
cell += char
escapeNext = false
} else if (char === '"' && i < (line.length - 1) && line[i + 1] === '"') {
} else if (char === '"' && i < (remaining.length - 1) && remaining[i + 1] === '"') {
cell += char
escapeNext = true
} else if (char === '"') {
Expand All @@ -235,7 +235,7 @@ function extractNextCell(line: string, separator: string): string[] {
cell += char
}
}
return [cell, separatorFound === false ? null : line.slice(cell.length + 1)]
return [cell, separatorFound ? remaining.slice(cell.length + 1) : null]
}

function extractAllRowCells(line: string, separator: string): string[] {
Expand Down
130 changes: 1 addition & 129 deletions CodeMirror6/NodeLib/src/CmKeymap.ts
Original file line number Diff line number Diff line change
@@ -1,135 +1,7 @@
import { toggleMarkdownBold, toggleMarkdownItalic } from "./CmCommands"
import { KeyBinding, EditorView } from '@codemirror/view'
import { EditorSelection, SelectionRange, Text } from "@codemirror/state"
import {
deleteCharBackward, deleteCharForward, deleteGroupBackward, deleteGroupForward,
cursorGroupLeft, cursorGroupRight, selectGroupLeft, selectGroupRight,
cursorCharLeft, cursorCharRight, selectCharLeft, selectCharRight,
} from '@codemirror/commands'
import { KeyBinding } from '@codemirror/view'

export const customMarkdownKeymap: KeyBinding[] = [
{ key: 'Mod-b', run: toggleMarkdownBold }, // Cmd/Ctrl + B for bold
{ key: 'Mod-i', run: toggleMarkdownItalic }, // Cmd/Ctrl + I for italics
]

export const multipleCursorDeleteKeymap = [
{ key: "Delete", run: deleteCharForward },
{ key: "Backspace", run: deleteCharBackward },
{ key: "Mod-Delete", run: deleteGroupForward },
{ key: "Mod-Backspace", run: deleteGroupBackward },
]

export const multipleCursorNavigationKeymap: KeyBinding[] = [
{
key: "ArrowLeft",
run: (view) => moveCursorsByCharacter(view, true, false),
shift: (view) => moveCursorsByCharacter(view, true, true),
},
{
key: "ArrowRight",
run: (view) => moveCursorsByCharacter(view, false, false),
shift: (view) => moveCursorsByCharacter(view, false, true),
},
{
key: "Mod-ArrowLeft",
run: (view) => moveCursorsByWord(view, true, false),
shift: (view) => moveCursorsByWord(view, true, true),
},
{
key: "Mod-ArrowRight",
run: (view) => moveCursorsByWord(view, false, false),
shift: (view) => moveCursorsByWord(view, false, true),
},
{
key: "Home",
run: (view) => moveCursorsToLineBoundaries(view, true, false),
shift: (view) => moveCursorsToLineBoundaries(view, true, true),
},
{
key: "End",
run: (view) => moveCursorsToLineBoundaries(view, false, false),
shift: (view) => moveCursorsToLineBoundaries(view, false, true),
},
]

function moveCursorsByCharacter(view: EditorView, previous: boolean, headOnly: boolean) {
const { state } = view
const newSelectionRanges: SelectionRange[] = []
for (const range of state.selection.ranges) {
const offset = previous ? -1 : 1
const newAnchor = headOnly ? range.anchor : Math.max(Math.min(state.doc.length, range.head + offset), 0)
const newHead = !headOnly ? newAnchor : Math.max(Math.min(state.doc.length, range.head + offset), 0)
newSelectionRanges.push(EditorSelection.range(newAnchor, newHead))
}
view.dispatch(state.update({
selection: EditorSelection.create(newSelectionRanges),
scrollIntoView: true,
userEvent: 'input'
}))
return true
}

function moveCursorsByWord(view: EditorView, previous: boolean, headOnly: boolean): boolean {
const { state } = view
const newSelectionRanges: SelectionRange[] = []

for (const range of state.selection.ranges) {
const currentPos = range.head
const wordBoundary = findWordBoundary(state.doc, currentPos, previous, true)

const newAnchor = headOnly ? range.anchor : wordBoundary
const newHead = !headOnly ? newAnchor : wordBoundary

newSelectionRanges.push(EditorSelection.range(newAnchor, newHead))
}
view.dispatch(state.update({
selection: EditorSelection.create(newSelectionRanges),
scrollIntoView: true,
userEvent: 'input'
}))
return true
}

function moveCursorsToLineBoundaries(view: EditorView, start: boolean, headOnly: boolean): boolean {
const { state } = view
const newSelectionRanges: SelectionRange[] = []
for (const range of state.selection.ranges) {
const currentPos = range.head
const startOfLine = state.doc.lineAt(currentPos).from
const endOfLine = state.doc.lineAt(currentPos).to
const lineBoundary = start ? startOfLine : endOfLine

const newAnchor = headOnly ? range.anchor : lineBoundary
const newHead = !headOnly ? newAnchor : lineBoundary

newSelectionRanges.push(EditorSelection.range(newAnchor, newHead))
}
view.dispatch(state.update({
selection: EditorSelection.create(newSelectionRanges),
scrollIntoView: true,
userEvent: 'input'
}))
return true
}

function findWordBoundary(doc: Text, pos: number, previous: boolean, firstRun: boolean): number {
if (previous && pos === 0) return 0
if (!previous && pos === doc.length) return doc.length
if (isWordBoundary(doc, pos) && firstRun) {
pos += previous ? -1 : 1
return findWordBoundary(doc, pos, previous, false)
}
for (let i = pos; previous ? i >= 0 : i < doc.length; i += (previous ? -1 : 1)) {
if (isWordBoundary(doc, i)) {
return i
}
}
return previous ? 0 : doc.length
}

function isWordBoundary(doc: Text, pos: number): boolean {
if (pos < 0 || pos >= doc.length) return true
const charBefore = doc.sliceString(pos - 1, pos)
const charAfter = doc.sliceString(pos, pos + 1)
return /\s/.test(charBefore) !== /\s/.test(charAfter)
}
40 changes: 4 additions & 36 deletions CodeMirror6/NodeLib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import {
} from "@codemirror/view"
import { EditorState, SelectionRange, Text, StateEffect, ChangeSpec } from "@codemirror/state"
import {
indentWithTab, history, historyKeymap,
cursorSyntaxLeft, selectSyntaxLeft, selectSyntaxRight, cursorSyntaxRight, deleteLine,
moveLineDown, moveLineUp, selectParentSyntax, indentLess, indentMore,
indentWithTab, history, historyKeymap, defaultKeymap, indentLess, indentMore,
copyLineUp, copyLineDown, indentSelection, cursorMatchingBracket, toggleComment, toggleBlockComment,
simplifySelection, insertBlankLine, selectLine, undo, redo, redoSelection, undoSelection,
blockComment, blockUncomment, toggleBlockCommentByLine, lineComment, lineUncomment, toggleLineComment,
Expand Down Expand Up @@ -61,7 +59,6 @@ import { getColumnStylingKeymap, columnStylingPlugin, columnLintSource, getSepar
import { consoleLog } from "./CmLogging"
import { createEditorWithId } from "./CmId"
import { hyperLink } from './CmHyperlink'
import { multipleCursorNavigationKeymap, multipleCursorDeleteKeymap } from "./CmKeymap"

export { getCmInstance }

Expand Down Expand Up @@ -147,41 +144,12 @@ export async function initCodeMirror(
linter(async view => maxDocLengthLintSource(id, view)),
keymap.of([
...closeBracketsKeymap,

//...defaultKeymap,
{ key: "Alt-ArrowLeft", mac: "Mod-ArrowLeft", run: cursorSyntaxLeft, shift: selectSyntaxLeft },
{ key: "Alt-ArrowRight", mac: "Mod-ArrowRight", run: cursorSyntaxRight, shift: selectSyntaxRight },

{ key: "Alt-ArrowUp", run: moveLineUp },
{ key: "Shift-Alt-ArrowUp", run: copyLineUp },

{ key: "Alt-ArrowDown", run: moveLineDown },
{ key: "Shift-Alt-ArrowDown", run: copyLineDown },

{ key: "Escape", run: simplifySelection },
{ key: "Mod-Enter", run: insertBlankLine },

{ key: "Alt-l", mac: "Mod-l", run: selectLine },
{ key: "Mod-i", run: selectParentSyntax, preventDefault: true },

{ key: "Mod-[", run: indentLess },
{ key: "Mod-]", run: indentMore },
{ key: "Mod-Alt-\\", run: indentSelection },

{ key: "Shift-Mod-k", run: deleteLine },

{ key: "Shift-Mod-\\", run: cursorMatchingBracket },

{ key: "Mod-/", run: toggleComment },
{ key: "Alt-A", run: toggleBlockComment },

...defaultKeymap,
...completionKeymap,
...lintKeymap,
...searchKeymap,
...historyKeymap,
...foldKeymap,
...completionKeymap,
...lintKeymap,
...multipleCursorDeleteKeymap,
...multipleCursorNavigationKeymap,
])
]

Expand Down
6 changes: 2 additions & 4 deletions Examples.BlazorServer/Controllers/FileUploadController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Examples.BlazorServer.Controllers;

Expand All @@ -13,12 +11,12 @@ public async Task<IActionResult> Upload(IFormFile file)
{
if (file == null || file.Length == 0)
{
return BadRequest("Upload a file.");
return await Task.FromResult(BadRequest("Upload a file."));
}

// Process the file here
// Example: Save the file to the server, database, etc.

return Ok(new { file.FileName, file.Length });
return await Task.FromResult(Ok(new { file.FileName, file.Length }));
}
}
2 changes: 1 addition & 1 deletion Examples.BlazorServer/Examples.BlazorServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>0.7.4</Version>
<Version>0.7.5</Version>
</PropertyGroup>
<ItemGroup>
<SupportedPlatform Include="browser" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<Version>0.7.4</Version>
<Version>0.7.5</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Sentry.AspNetCore" Version="4.1.0" />
Expand Down
Loading

0 comments on commit 1cc3763

Please sign in to comment.