Skip to content

Commit

Permalink
feat: extraction button in subtree, close #510
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Mar 31, 2021
1 parent bd7f28a commit 73bc114
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@
{
"command": "i18n-ally.extract-text",
"category": "%extname%",
"title": "%refactor.extract_text%"
"title": "%refactor.extract_text%",
"icon": "$(symbol-string)"
},
{
"command": "i18n-ally.extraction-detect-current-file",
Expand Down Expand Up @@ -547,6 +548,11 @@
"command": "i18n-ally.open-docs-hard-string",
"when": "viewItem =~ /i18n-ally-hard-string-root/",
"group": "inline@1"
},
{
"command": "i18n-ally.extract-text",
"when": "viewItem =~ /i18n-ally-hard-string-item/",
"group": "inline@1"
}
],
"view/title": [
Expand Down
40 changes: 27 additions & 13 deletions src/views/items/HardStringDetectResultItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,44 @@ import { ExtensionContext, Range, TreeItemCollapsibleState } from 'vscode'
import { BaseTreeItem } from './Base'
import { DetectionResult } from '~/extraction'
import { Commands } from '~/commands'
import { ExtractTextOptions } from '~/commands/extractText'

export class HardStringDetectResultItem extends BaseTreeItem {
export class HardStringDetectResultItem extends BaseTreeItem implements ExtractTextOptions {
collapsibleState = TreeItemCollapsibleState.None
filepath: string
text: string
range: Range
languageId?: string | undefined
isInsert?: boolean | undefined

constructor(
readonly ctx: ExtensionContext,
public readonly detection: DetectionResult,
) {
super(ctx)

const document = this.detection.document!

this.languageId = document.languageId
this.filepath = document.fileName
this.text = detection.text
this.isInsert = false

this.contextValue = 'i18n-ally-hard-string-item'
this.label = this.detection.text.trim()

if (this.detection.editor && this.detection.document) {
this.command = {
title: 'Go To',
command: Commands.go_to_range,
arguments: [
this.detection.editor,
new Range(
this.detection.document.positionAt(this.detection.start),
this.detection.document.positionAt(this.detection.end),
),
],
}
this.range = new Range(
document.positionAt(this.detection.start),
document.positionAt(this.detection.end),
)

this.command = {
title: 'Go To',
command: Commands.go_to_range,
arguments: [
this.detection.editor,
this.range,
],
}
}
}
4 changes: 2 additions & 2 deletions src/views/items/LocaleTreeItem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExtensionContext, TreeItemCollapsibleState } from 'vscode'
import { ExtensionContext, TreeItemCollapsibleState, Command } from 'vscode'
import { EditorPanel } from '../../webview/panel'
import { BaseTreeItem } from './Base'
import { decorateLocale, NodeHelper, resolveFlattenRootKeypath, ROOT_KEY, resolveFlattenRoot } from '~/utils'
Expand Down Expand Up @@ -122,7 +122,7 @@ export class LocaleTreeItem extends BaseTreeItem {
}

// @ts-expect-error
get command() {
get command(): Command | undefined {
if (this.editorMode) {
return {
command: Commands.open_in_editor,
Expand Down

0 comments on commit 73bc114

Please sign in to comment.