Documentation
¶
Overview ¶
Package quickdiffpeek is the peek of a change of the quick diff (SPEC §10.30 "The peek", step 24.12): a view zone under a changed block of lines of an editor, with a title bar (the provider's label, "Change 2 of 5", the actions the extensions put in the menu of the peek, and the arrows and the close button) over a small diff editor of the original and the modified text of the change. The Controller is what the editor of a file holds (editor.QuickDiffPeeker); the window gives it the model of the changes and makes the small diff editor, so the package knows nothing of how documents and editors are made.
Ported from VS Code: src/vs/workbench/contrib/scm/browser/quickDiffWidget.ts
Index ¶
- type Action
- type Body
- type BodySpec
- type Config
- type Controller
- func (c *Controller) Actions() []Action
- func (c *Controller) AddListener(fn foundation.VoidCallback) foundation.ListenerHandle
- func (c *Controller) Body() *Body
- func (c *Controller) CanNavigate() bool
- func (c *Controller) Click(line int)
- func (c *Controller) Close()
- func (c *Controller) Dispose()
- func (c *Controller) Index() int
- func (c *Controller) ProviderID() string
- func (c *Controller) RemoveListener(h foundation.ListenerHandle)
- func (c *Controller) Shown() (Shown, bool)
- func (c *Controller) Step(next bool)
- func (c *Controller) Title() string
- func (c *Controller) ToggleFocus()
- func (c *Controller) Visible() bool
- type Model
- type Shown
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct {
// Icon is the Codicon (a fonts.Codicon... constant) and Tooltip the hover.
Icon int
Tooltip string
// Run is called when the button is pressed; the peek closes after it, as VS Code's does after an action that succeeded.
Run func()
}
Action is a button of the title bar: an icon with a tooltip that runs a command of the menu of the peek.
type Body ¶
type Body struct {
// Widget is the diff editor, as wide and as tall as the zone leaves it.
Widget widgets.Widget
// Reveal scrolls the diff editor so that the change is in the middle of it.
Reveal func(c quickdiff.Change)
// Focus gives the keyboard to the editor of the modified text, and HasFocus tells whether it has it.
Focus func()
HasFocus func() bool
// Dispose lets go of the editors and the documents of the body.
Dispose func()
}
Body is the small diff editor of the peek: the original of a provider on one side and the document of the editor on the other, in one column (VS Code's EmbeddedDiffEditorWidget with renderSideBySide off).
type BodySpec ¶
type BodySpec struct {
// ProviderID and Label are the provider's; Original is the URI of its original document and Text its text.
ProviderID, Label, Original, Text string
// Peeker is the controller; the editors of the body give it to their view models, so that Escape in the peek closes it.
Peeker editor.QuickDiffPeeker
}
BodySpec is what the window makes a Body from.
type Config ¶
type Config struct {
// Editor is the editor of the file the peek is shown in.
Editor *editor.ViewModel
// Model is the model of the changes of the document of the editor.
Model Model
// Name is the title of the peek, the name of the file.
Name func() string
// NewBody makes the small diff editor of a provider's original. It is called when the peek opens and again when the original changes.
NewBody func(BodySpec) (Body, error)
// Actions are the buttons the menu of the peek puts in the title bar for the change, in the order they are shown.
Actions func(Shown) []Action
// FocusEditor gives the keyboard to the editor.
FocusEditor func()
// OnError is told about a body that could not be made.
OnError func(error)
}
Config configures a Controller.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller is the peek of the changes of one editor. It is used on the UI thread only.
func New ¶
func New(cfg Config) *Controller
New makes the peek of an editor. It follows the model for as long as it lives; Dispose stops it.
func (*Controller) Actions ¶
func (c *Controller) Actions() []Action
Actions are the buttons of the title bar for the change shown.
func (*Controller) AddListener ¶
func (c *Controller) AddListener(fn foundation.VoidCallback) foundation.ListenerHandle
AddListener calls fn when the peek opens, moves, changes or closes.
func (*Controller) Body ¶
func (c *Controller) Body() *Body
Body is the small diff editor of the peek; nil while it is closed.
func (*Controller) CanNavigate ¶
func (c *Controller) CanNavigate() bool
CanNavigate says that Step can move: the peek is closed (it opens on a change), or there is more than one change.
func (*Controller) Click ¶
func (c *Controller) Click(line int)
Click implements editor.QuickDiffPeeker: the peek of the change at the line opens, or closes when it shows that change.
Ported from VS Code: quickDiffWidget.ts (QuickDiffEditorController.onEditorMouseUp)
func (*Controller) Close ¶
func (c *Controller) Close()
Close implements editor.QuickDiffPeeker: the peek goes, and the keyboard is the editor's.
func (*Controller) Dispose ¶
func (c *Controller) Dispose()
Dispose closes the peek and stops following the model.
func (*Controller) Index ¶
func (c *Controller) Index() int
Index is the change shown among the changes of the model, -1 while the peek is closed.
func (*Controller) ProviderID ¶
func (c *Controller) ProviderID() string
ProviderID is the provider of the change shown, empty while the peek is closed.
func (*Controller) RemoveListener ¶
func (c *Controller) RemoveListener(h foundation.ListenerHandle)
RemoveListener removes a listener of AddListener.
func (*Controller) Shown ¶
func (c *Controller) Shown() (Shown, bool)
Shown describes the change the peek shows; false while it is closed.
func (*Controller) Step ¶
func (c *Controller) Step(next bool)
Step implements editor.QuickDiffPeeker: the first step opens the peek at the first change that ends at or after the line of the cursor (before it, going back), the next ones go round the changes of the provider of the change shown.
Ported from VS Code: quickDiffWidget.ts (QuickDiffEditorController.next, previous and assertWidget)
func (*Controller) Title ¶
func (c *Controller) Title() string
Title is the name of the file the title bar shows.
func (*Controller) ToggleFocus ¶
func (c *Controller) ToggleFocus()
ToggleFocus implements editor.QuickDiffPeeker: the keyboard goes into the small diff editor, or back to the editor.
func (*Controller) Visible ¶
func (c *Controller) Visible() bool
Visible implements editor.QuickDiffPeeker.
type Model ¶
type Model interface {
// Result is the providers and the changes, sorted by their place in the text.
Result() quickdiff.Result
// OnChange calls fn when the result changes and returns the function that stops it.
OnChange(fn func()) (stop func())
// OriginalText is the text the provider with the id was compared with; false when the model does not have it.
OriginalText(providerID string) (string, bool)
}
Model is what the peek reads of the changes of the document of its editor: the result of the model of the quick diff, with the text of the originals.
type Shown ¶
type Shown struct {
// ProviderID, Label and Original are those of the provider.
ProviderID, Label, Original string
// Change is the change, Index its place among Changes, the changes of the provider in the order of the text.
Change quickdiff.Change
Index int
Changes []quickdiff.Change
// Total is the number of changes of every provider (the title says "change" for one).
Total int
}
Shown is the change the peek shows, with the changes of its provider.