wrap

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package wrap computes where word wrap breaks a line into rows (SPEC §9.2): the algorithm of VS Code's monospace line breaks computer, which counts columns, for lines whose characters have the width of one or two columns, and the helpers the editor uses for the other lines, which it breaks by laying the text out. It has no dependency on the UI.

Ported from VS Code: src/vs/editor/common/viewModel/monospaceLineBreaksComputer.ts

Index

Constants

View Source
const (
	DefaultBreakBefore = "([{‘“〈《「『【〔([{「£¥$£¥++"
	DefaultBreakAfter  = "" /* 275-byte string literal not displayed */
)

Default break characters of VS Code (editor.wordWrapBreakBeforeCharacters and editor.wordWrapBreakAfterCharacters): a row may break before one of the first and after one of the second, which also name where the ideographic and the kinsoku shori rules apply.

Variables

This section is empty.

Functions

func IndentColumns

func IndentColumns(line string, o Options) int

IndentColumns is the number of columns continuation rows of a line are indented by, as Compute gives them: for a line that is broken another way (by laying the text out).

Types

type Breaks

type Breaks struct {
	// Offsets are the byte offsets where the rows end: row i is the text from Offsets[i-1] (0
	// for the first row) to Offsets[i]; the last is the length of the line.
	Offsets []int
	// VisibleColumns are the visible columns of the line at those offsets.
	VisibleColumns []int
	// IndentLength is the number of columns continuation rows are indented by.
	IndentLength int
}

Breaks says how a line is split into rows.

func Compute

func Compute(line string, o Options) *Breaks

Compute breaks a line into rows of o.Column columns, breaking at the best place before the column (after a space, before a bracket, between ideographs), or at the column when there is none. It returns nil when the line fits in one row. Tabs go to the next tab stop and a character of more than one code unit is never split.

Ported from VS Code: src/vs/editor/common/viewModel/monospaceLineBreaksComputer.ts (createLineBreaks)

func (*Breaks) RowCount

func (b *Breaks) RowCount() int

RowCount is the number of rows.

func (*Breaks) RowEnd

func (b *Breaks) RowEnd(row int) int

RowEnd is the byte offset where a row ends, or -1 for the end of the line when b is nil.

func (*Breaks) RowOf

func (b *Breaks) RowOf(offset int) int

RowOf is the row that shows a byte offset of the line: an offset where a row starts is on that row, and the end of the line is on the last.

func (*Breaks) RowStart

func (b *Breaks) RowStart(row int) int

RowStart is the byte offset where a row starts.

type Indent

type Indent int

Indent is how continuation rows are indented (editor.wrappingIndent).

const (
	// IndentNone starts continuation rows at the left edge.
	IndentNone Indent = iota
	// IndentSame indents them as the line is.
	IndentSame
	// IndentIndent indents them one tab more than the line.
	IndentIndent
	// IndentDeepIndent indents them two tabs more than the line.
	IndentDeepIndent
)

func ParseIndent

func ParseIndent(s string) Indent

ParseIndent reads a value of editor.wrappingIndent: "none", "same", "indent" or "deepIndent"; anything else is "same", VS Code's default.

type Options

type Options struct {
	// TabSize is the distance between tab stops, in columns.
	TabSize int
	// Column is the number of columns of a row, 1 or more.
	Column int
	// Indent is how continuation rows are indented.
	Indent Indent
	// BreakBefore and BreakAfter are the characters a row may break before and after; empty
	// strings break nowhere but at the column.
	BreakBefore, BreakAfter string
	// KeepAll keeps words of ideographs together (editor.wordBreak "keepAll").
	KeepAll bool
	// FullWidthColumns is how many columns a full-width character takes; 0 means 2.
	FullWidthColumns int
}

Options are what the breaking of a line depends on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL