mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
better current query UX
This commit is contained in:
parent
6930a2543c
commit
42d7166d2b
@ -40,6 +40,8 @@ export interface SplitResultItemRich {
|
|||||||
text: string;
|
text: string;
|
||||||
start: SplitPositionDefinition;
|
start: SplitPositionDefinition;
|
||||||
end: SplitPositionDefinition;
|
end: SplitPositionDefinition;
|
||||||
|
trimStart?: SplitPositionDefinition;
|
||||||
|
trimEnd?: SplitPositionDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SplitResultItem = string | SplitResultItemRich;
|
export type SplitResultItem = string | SplitResultItemRich;
|
||||||
@ -211,7 +213,7 @@ function pushQuery(context: SplitLineContext) {
|
|||||||
if (trimmed) {
|
if (trimmed) {
|
||||||
if (context.options.returnRichInfo) {
|
if (context.options.returnRichInfo) {
|
||||||
context.pushOutput(
|
context.pushOutput(
|
||||||
trimPositions(sql, {
|
countTrimmedPositions(sql, {
|
||||||
text: trimmed,
|
text: trimmed,
|
||||||
|
|
||||||
start: {
|
start: {
|
||||||
@ -233,26 +235,26 @@ function pushQuery(context: SplitLineContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function trimPositions(full: string, positions: SplitResultItemRich): SplitResultItemRich {
|
function countTrimmedPositions(full: string, positions: SplitResultItemRich): SplitResultItemRich {
|
||||||
const startIndex = full.indexOf(positions.text);
|
const startIndex = full.indexOf(positions.text);
|
||||||
const res = {
|
|
||||||
...positions,
|
const trimStart = { ...positions.start };
|
||||||
start: {
|
|
||||||
...positions.start,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
for (let i = 0; i < startIndex; i += 1) {
|
for (let i = 0; i < startIndex; i += 1) {
|
||||||
if (full[i] == '\n') {
|
if (full[i] == '\n') {
|
||||||
res.start.position += 1;
|
trimStart.position += 1;
|
||||||
res.start.line += 1;
|
trimStart.line += 1;
|
||||||
res.start.column = 0;
|
trimStart.column = 0;
|
||||||
} else {
|
} else {
|
||||||
res.start.position += 1;
|
trimStart.position += 1;
|
||||||
res.start.column += 1;
|
trimStart.column += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return {
|
||||||
|
...positions,
|
||||||
|
trimStart,
|
||||||
|
trimEnd: positions.end,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function markStartCommand(context: SplitLineContext) {
|
function markStartCommand(context: SplitLineContext) {
|
||||||
@ -330,7 +332,7 @@ export function finishSplitStream(context: SplitStreamContext) {
|
|||||||
if (trimmed) {
|
if (trimmed) {
|
||||||
if (context.options.returnRichInfo) {
|
if (context.options.returnRichInfo) {
|
||||||
context.pushOutput(
|
context.pushOutput(
|
||||||
trimPositions(context.commandPart, {
|
countTrimmedPositions(context.commandPart, {
|
||||||
text: trimmed,
|
text: trimmed,
|
||||||
|
|
||||||
start: {
|
start: {
|
||||||
@ -364,12 +366,16 @@ export function splitQuery(sql: string, options: SplitterOptions = null): SplitR
|
|||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
text: sql,
|
text: sql,
|
||||||
startLine: 0,
|
start: {
|
||||||
startPosition: 0,
|
position: 0,
|
||||||
startColumn: 0,
|
line: 0,
|
||||||
endLine: lines.length,
|
column: 0,
|
||||||
endColumn: lines[lines.length - 1]?.length || 0,
|
},
|
||||||
endPosition: sql.length,
|
end: {
|
||||||
|
position: sql.length,
|
||||||
|
line: lines.length,
|
||||||
|
column: lines[lines.length - 1]?.length || 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ test('count lines', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
text: 'SELECT * FROM `table1`',
|
text: 'SELECT * FROM `table1`',
|
||||||
|
|
||||||
start: expect.objectContaining({
|
trimStart: expect.objectContaining({
|
||||||
position: 0,
|
position: 0,
|
||||||
line: 0,
|
line: 0,
|
||||||
column: 0,
|
column: 0,
|
||||||
@ -115,7 +115,7 @@ test('count lines', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
text: 'SELECT * FROM `table2`',
|
text: 'SELECT * FROM `table2`',
|
||||||
|
|
||||||
start: expect.objectContaining({
|
trimStart: expect.objectContaining({
|
||||||
position: 24,
|
position: 24,
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 0,
|
column: 0,
|
||||||
@ -141,7 +141,7 @@ test('count lines with flush', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
text: 'SELECT * FROM `table1`',
|
text: 'SELECT * FROM `table1`',
|
||||||
|
|
||||||
start: expect.objectContaining({
|
trimStart: expect.objectContaining({
|
||||||
position: 0,
|
position: 0,
|
||||||
line: 0,
|
line: 0,
|
||||||
column: 0,
|
column: 0,
|
||||||
@ -156,7 +156,7 @@ test('count lines with flush', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
text: 'SELECT * FROM `table2`',
|
text: 'SELECT * FROM `table2`',
|
||||||
|
|
||||||
start: expect.objectContaining({
|
trimStart: expect.objectContaining({
|
||||||
position: 24,
|
position: 24,
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 0,
|
column: 0,
|
||||||
|
@ -189,13 +189,11 @@
|
|||||||
|
|
||||||
currentPart = part;
|
currentPart = part;
|
||||||
if (currentPart) {
|
if (currentPart) {
|
||||||
|
const start = currentPart.trimStart || currentPart.start;
|
||||||
|
const end = currentPart.trimEnd || currentPart.end;
|
||||||
currentPartMarker = editor
|
currentPartMarker = editor
|
||||||
.getSession()
|
.getSession()
|
||||||
.addMarker(
|
.addMarker(new ace.Range(start.line, start.column, end.line, end.column), 'ace_active-line', 'text');
|
||||||
new ace.Range(currentPart.start.line, currentPart.start.column, currentPart.end.line, currentPart.end.column),
|
|
||||||
'ace_active-line',
|
|
||||||
'text'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user