Compare commits
No commits in common. "main" and "v0.1.8" have entirely different histories.
|
|
@ -12,19 +12,11 @@ class TextProcessor {
|
||||||
setCodeMirrorEditor(editor) {
|
setCodeMirrorEditor(editor) {
|
||||||
this._editor = editor;
|
this._editor = editor;
|
||||||
window.runtime.EventsOn("process-text-response", (data) => {
|
window.runtime.EventsOn("process-text-response", (data) => {
|
||||||
const cursorPos = this._editor.state.selection.main.head;
|
|
||||||
const appendInsertPos = this._appendInsertPos;
|
|
||||||
this._appendInsertPos = undefined;
|
|
||||||
let newSelection;
|
|
||||||
const changes = data.output.map(span => {
|
const changes = data.output.map(span => {
|
||||||
if (span.append) {
|
if (span.append) {
|
||||||
const insertAt = appendInsertPos !== undefined ? appendInsertPos : span.pos + span.len;
|
|
||||||
if (cursorPos === insertAt) {
|
|
||||||
newSelection = { anchor: insertAt + span.text.length };
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
from: insertAt,
|
from: span.pos + span.len,
|
||||||
to: insertAt,
|
to: span.pos + span.len,
|
||||||
insert: span.text,
|
insert: span.text,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -35,11 +27,7 @@ class TextProcessor {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const transaction = { changes: changes };
|
this._editor.dispatch({ changes: changes });
|
||||||
if (newSelection) {
|
|
||||||
transaction.selection = newSelection;
|
|
||||||
}
|
|
||||||
this._editor.dispatch(transaction);
|
|
||||||
});
|
});
|
||||||
window.runtime.EventsOn("request-text-process", (data) => {
|
window.runtime.EventsOn("request-text-process", (data) => {
|
||||||
this.runTextCommand(data.action);
|
this.runTextCommand(data.action);
|
||||||
|
|
@ -56,14 +44,12 @@ class TextProcessor {
|
||||||
|
|
||||||
let inputs = [];
|
let inputs = [];
|
||||||
if (shouldBeAll) {
|
if (shouldBeAll) {
|
||||||
this._appendInsertPos = this._editor.state.selection.main.head;
|
|
||||||
inputs.push({
|
inputs.push({
|
||||||
text: this._editor.state.doc.toString(),
|
text: this._editor.state.doc.toString(),
|
||||||
pos: 0,
|
pos: 0,
|
||||||
len: this._editor.state.doc.length,
|
len: this._editor.state.doc.length,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this._appendInsertPos = undefined;
|
|
||||||
inputs = ranges.map(r => ({
|
inputs = ranges.map(r => ({
|
||||||
text: this._editor.state.doc.slice(r.from, r.to).toString(),
|
text: this._editor.state.doc.slice(r.from, r.to).toString(),
|
||||||
pos: r.from,
|
pos: r.from,
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -3,7 +3,6 @@ module dequoter
|
||||||
go 1.25
|
go 1.25
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/google/uuid v1.6.0
|
|
||||||
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
|
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
|
||||||
github.com/wailsapp/wails/v2 v2.10.2
|
github.com/wailsapp/wails/v2 v2.10.2
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
|
|
@ -50,6 +49,7 @@ require (
|
||||||
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
|
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
|
||||||
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||||
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
|
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/gorilla/websocket v1.5.3 // indirect
|
github.com/gorilla/websocket v1.5.3 // indirect
|
||||||
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
|
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
|
||||||
github.com/labstack/echo/v4 v4.13.3 // indirect
|
github.com/labstack/echo/v4 v4.13.3 // indirect
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ import (
|
||||||
|
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"ucl.lmika.dev/ucl"
|
"ucl.lmika.dev/ucl"
|
||||||
)
|
)
|
||||||
|
|
@ -61,25 +60,14 @@ var TextFilters = map[string]TextProcessor{
|
||||||
return TextFilterResponse{Output: strings.ToLower(input)}, nil
|
return TextFilterResponse{Output: strings.ToLower(input)}, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"quote": {
|
|
||||||
Label: "String: Quote",
|
|
||||||
Filter: func(ctx context.Context, input string) (resp TextFilterResponse, err error) {
|
|
||||||
return TextFilterResponse{Output: strconv.Quote(input)}, nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"unquote": {
|
"unquote": {
|
||||||
Label: "String: Unquote",
|
Label: "String: Unquote",
|
||||||
Filter: func(ctx context.Context, input string) (resp TextFilterResponse, err error) {
|
Filter: func(ctx context.Context, input string) (resp TextFilterResponse, err error) {
|
||||||
endNL := ""
|
out, err := strconv.Unquote(input)
|
||||||
if strings.HasSuffix(input, "\n") {
|
|
||||||
endNL = "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
out, err := strconv.Unquote(strings.TrimSpace(input))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return TextFilterResponse{}, err
|
return TextFilterResponse{}, err
|
||||||
}
|
}
|
||||||
return TextFilterResponse{Output: out + endNL}, nil
|
return TextFilterResponse{Output: out}, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"join-lines-with-commas": {
|
"join-lines-with-commas": {
|
||||||
|
|
@ -188,20 +176,6 @@ var TextFilters = map[string]TextProcessor{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"uuid": {
|
|
||||||
Label: "Generate: UUID v4",
|
|
||||||
Filter: func(ctx context.Context, input string) (resp TextFilterResponse, err error) {
|
|
||||||
u, err := uuid.NewRandom()
|
|
||||||
if err != nil {
|
|
||||||
return TextFilterResponse{}, fmt.Errorf("failed to generate UUID: %w", err)
|
|
||||||
}
|
|
||||||
return TextFilterResponse{
|
|
||||||
Output: u.String(),
|
|
||||||
Append: true,
|
|
||||||
}, nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
"lines": {
|
"lines": {
|
||||||
Label: "Lines: Count",
|
Label: "Lines: Count",
|
||||||
Analyze: func(ctx context.Context, input string) (result string, err error) {
|
Analyze: func(ctx context.Context, input string) (result string, err error) {
|
||||||
|
|
@ -291,6 +265,22 @@ var TextFilters = map[string]TextProcessor{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"ucl-evaluate": {
|
||||||
|
Label: "UCL: Evaluate",
|
||||||
|
Description: "Evaluates the input as a UCL expression and displays the result in the status bar.",
|
||||||
|
Analyze: func(ctx context.Context, input string) (result string, err error) {
|
||||||
|
res, err := uclInstFromContext(ctx).EvalString(ctx, input)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, ucl.ErrNotConvertable) {
|
||||||
|
return "Evaluated successfully. No result.", err
|
||||||
|
}
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("Result: %v", res), nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
"sort-lines-asc": {
|
"sort-lines-asc": {
|
||||||
Label: "Lines: Sort A-Z",
|
Label: "Lines: Sort A-Z",
|
||||||
Filter: func(ctx context.Context, input string) (resp TextFilterResponse, err error) {
|
Filter: func(ctx context.Context, input string) (resp TextFilterResponse, err error) {
|
||||||
|
|
@ -366,6 +356,22 @@ var TextFilters = map[string]TextProcessor{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"ucl-replace": {
|
||||||
|
Label: "UCL: Replace",
|
||||||
|
Description: "Evaluates the input as a UCL expression and replaces it with the result.",
|
||||||
|
Filter: func(ctx context.Context, input string) (resp TextFilterResponse, err error) {
|
||||||
|
res, err := uclInstFromContext(ctx).EvalString(ctx, input)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, ucl.ErrNotConvertable) {
|
||||||
|
return TextFilterResponse{}, err
|
||||||
|
}
|
||||||
|
return TextFilterResponse{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return TextFilterResponse{Output: fmt.Sprint(res)}, nil
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
type strPseudoVar struct {
|
type strPseudoVar struct {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue