direction: right
api: viewer/common/editor_api {
grid-columns: 1
ev: cursor / model / scroll events
en: option enums
}
consumers: consumers {
grid-columns: 2
root: root viewer facade
cursor: viewer/common/cursor
vm: viewer/common/view_model
vl: viewer/common/view_layout
br: internal/viewer/browser/*
fold: contrib/folding
}
consumers -> api: "import the one declaration" {style.stroke-dash: 3}
api -> consumers: "no dependency back" {style.stroke: red}///|
test "every cursor change carries a reason" {
let reasons : Array[@editor_api.CursorChangeReason] = [
NotSet,
ContentFlush,
RecoverFromMarkers,
Explicit,
Paste,
Undo,
Redo,
]
debug_inspect(
reasons,
content=(
#|[
#| NotSet,
#| ContentFlush,
#| RecoverFromMarkers,
#| Explicit,
#| Paste,
#| Undo,
#| Redo,
#|]
),
)
}///|
test "a selection event pairs new and old state with model versions" {
let event : @editor_api.CursorSelectionChangedEvent = {
selection: Selection(Position(2, 1), Position(2, 8)),
secondary_selections: [],
model_version_id: 7,
old_selections: Some([Selection(Position(1, 1), Position(1, 1))]),
old_model_version_id: 6,
source: "mouse",
reason: Explicit,
}
debug_inspect(
(
event.reason,
event.source,
event.model_version_id,
event.old_model_version_id,
event.selection.is_empty(),
event.old_selections.map(previous => previous.length()),
),
content=(
#|(Explicit, "mouse", 7, 6, false, Some(1))
),
)
}///|
test "scroll events flag which axes actually moved" {
let event : @editor_api.ScrollEvent = {
scroll_top: 120.0,
scroll_left: 0.0,
scroll_width: 800.0,
scroll_height: 4000.0,
scroll_top_changed: true,
scroll_left_changed: false,
scroll_width_changed: false,
scroll_height_changed: false,
}
debug_inspect(
(
event.scroll_top_changed,
event.scroll_left_changed,
// a vertical-only listener can early-out on this
event.scroll_top_changed || event.scroll_height_changed,
),
content=(
#|(true, false, true)
),
)
}///|
test "a model change has an absent side at attach and at detach" {
let uri = @base_common.Uri::parse("file:///src/main.mbt")
let attach : @editor_api.ModelChangedEvent = {
old_model_url: None,
new_model_url: Some(uri),
}
let detach : @editor_api.ModelChangedEvent = {
old_model_url: Some(uri),
new_model_url: None,
}
debug_inspect(
(
(attach.old_model_url is None, attach.new_model_url is None),
(detach.old_model_url is None, detach.new_model_url is None),
),
content=(
#|((true, false), (false, true))
),
)
}///|
test "a scrolled visible position is a box in viewport coordinates" {
let at : @editor_api.ScrolledVisiblePosition = {
top: 42.0,
left: 96.0,
height: 18.0,
}
debug_inspect(
(at.top, at.left, at.height),
content=(
#|(42, 96, 18)
),
)
}///|
test "the five option enums and their variants" {
let wrapping : Array[@editor_api.WrappingIndent] = [
None,
Same,
Indent,
DeepIndent,
]
let whitespace : Array[@editor_api.RenderWhitespace] = [
None,
Boundary,
Selection,
Trailing,
All,
]
let line_highlight : Array[@editor_api.RenderLineHighlight] = [
None,
Gutter,
Line,
All,
]
let validation : Array[@editor_api.RenderValidationDecorations] = [
Editable,
On,
Off,
]
let folding : Array[@editor_api.ShowFoldingControls] = [
Always,
Never,
Mouseover,
]
debug_inspect(
(wrapping, whitespace, line_highlight, validation, folding),
content=(
#|(
#| [None, Same, Indent, DeepIndent],
#| [None, Boundary, Selection, Trailing, All],
#| [None, Gutter, Line, All],
#| [Editable, On, Off],
#| [Always, Never, Mouseover],
#|)
),
)
}moon test --target js viewer/common/editor_api
moon test --target native viewer/common/editor_apipub(all) struct CursorPositionChangedEvent {
position : Position
secondary_positions : Array[Position]
reason : CursorChangeReason
source : String
} derive(Debug)fn RenderValidationDecorations::equal(RenderValidationDecorations, RenderValidationDecorations) -> Boolfn RenderValidationDecorations::not_equal(x : RenderValidationDecorations, y : RenderValidationDecorations) -> Boolpub(all) struct ScrollEvent {
scroll_top : Double
scroll_left : Double
scroll_width : Double
scroll_height : Double
scroll_top_changed : Bool
scroll_left_changed : Bool
scroll_width_changed : Bool
scroll_height_changed : Bool
} derive(Debug)fn ScrolledVisiblePosition::not_equal(x : ScrolledVisiblePosition, y : ScrolledVisiblePosition) -> BoolInstall
Download zipReadonly MoonBit code viewer harness inspired by Monaco and CodeMirror.