code stringlengths 24 2.07M | docstring stringlengths 25 85.3k | func_name stringlengths 1 92 | language stringclasses 1
value | repo stringlengths 5 64 | path stringlengths 4 172 | url stringlengths 44 218 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
reduceOt = function(currentAdvance, char) {
return currentAdvance + calcCharAdvanceOpenType(char, fontSize, font, unitsPerEm)
} | Tests various string widths and compares the advance width (in pixels) results between OpenType.js and
the canvas fallback mechanism which returns the browser's actual rendered font width.
@type {Function} | reduceOt | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
reduceCanvas = function(currentAdvance, char) {
return currentAdvance + calcTextAdvanceCanvas(char, fontSize, font)
} | Tests various string widths and compares the advance width (in pixels) results between OpenType.js and
the canvas fallback mechanism which returns the browser's actual rendered font width.
@type {Function} | reduceCanvas | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
reduceCanvas = function(currentAdvance, char) {
return currentAdvance + calcTextAdvanceCanvas(char, fontSize, font)
} | Tests various string widths and compares the advance width (in pixels) results between OpenType.js and
the canvas fallback mechanism which returns the browser's actual rendered font width.
@type {Function} | reduceCanvas | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
function calcCharAdvance(char, fontSize, font, unitsPerEm) {
return isOpenTypeJsReliable(fontSize, font, unitsPerEm) ?
calcCharAdvanceOpenType(char, fontSize, font, unitsPerEm) :
calcTextAdvanceCanvas(char, fontSize, font)
} | Calculate the advance in pixels for a given char. In some browsers/platforms/font sizes, the fonts are not
rendered according to the specs in the font (see
http://stackoverflow.com/questions/30922573/firefox-rendering-of-opentype-font-does-not-match-the-font-specification).
Therefore, ensure the font spec matches the a... | calcCharAdvance | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
function calcReplicaCharAdvance(replicaChar, fontSize, fonts, minFontSize, unitsPerEm) {
let style = charFontStyle(replicaChar)
let charFontSize = calcFontSizeFromAttributes(fontSize, minFontSize, replicaChar.attributes)
return calcCharAdvance(replicaChar.char, charFontSize, fonts[style], unitsPerEm)
} | Calculate the advance in pixels for a given char. In some browsers/platforms/font sizes, the fonts are not
rendered according to the specs in the font (see
http://stackoverflow.com/questions/30922573/firefox-rendering-of-opentype-font-does-not-match-the-font-specification).
Therefore, ensure the font spec matches the a... | calcReplicaCharAdvance | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
setConfig(config) {
this.config = config
} | Calculate the advance in pixels for a given char. In some browsers/platforms/font sizes, the fonts are not
rendered according to the specs in the font (see
http://stackoverflow.com/questions/30922573/firefox-rendering-of-opentype-font-does-not-match-the-font-specification).
Therefore, ensure the font spec matches the a... | setConfig | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
fontScale(fontSize) {
return calcFontScale(fontSize, this.config.unitsPerEm)
} | Get the font scale to convert between font units and pixels for the given font size.
@param fontSize
@return {number} | fontScale | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
fontSizeFromAttributes(fontSize, attributes) {
return calcFontSizeFromAttributes(fontSize, this.config.minFontSize, attributes)
} | Return the font size given the default font size and current attributes.
@param fontSize
@param attributes | fontSizeFromAttributes | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
replicaCharAdvance(char, fontSize) {
return calcReplicaCharAdvance(char, fontSize, this.config.fonts, this.config.minFontSize, this.config.unitsPerEm)
} | Determines the advance for a given replica char.
@param char The replica char object.
@param fontSize
@return {number} | replicaCharAdvance | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
charAdvance(char, fontSize, font) {
return calcCharAdvance(char, fontSize, font, this.config.unitsPerEm)
} | Determines the advance for a given char. Since it is not a replica char, the font style and other attribute
information cannot be determined. A normal weight, non-decorated font with no special attributes is assumed. | charAdvance | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
advanceXForSpace(fontSize) {
return this.charAdvance(' ', fontSize, this.config.fonts.regular)
} | Returns the advance width in pixels for a space character in the normal style. | advanceXForSpace | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
indexAndCursorForXValue(fontSize, pixelValue, chars) {
let minFontSize = this.config.minFontSize
fontSize = fontSize > minFontSize ? fontSize : minFontSize
let currentWidthPx = 0
let index = 0
for(let i = 0; i < chars.length; i++) {
let glyphAdvancePx = this.replicaCharAdvance(chars[i], fontSi... | Obtain an Object with the char id and cursor position for a given pixel value. This is used to
set the current character and position the cursor correctly on a mouse click. If the target position
is past the last character, the index of the last character is returned.
@param {number} fontSize
@param {number} pixelValue... | indexAndCursorForXValue | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
advanceXForChars(fontSize, chars) {
let minFontSize = this.config.minFontSize
fontSize = fontSize > minFontSize ? fontSize : minFontSize
if(_.isArray(chars)) {
return chars.reduce((currentWidthPx, char) => {
return currentWidthPx + this.replicaCharAdvance(char, fontSize)
}, 0)
} else... | Get the advance width in pixels for the given char or chars.
@param {number} fontSize
@param {object|Array} chars
@return {number} | advanceXForChars | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
lineHeight(fontSize) {
let fontHeader = this.config.fonts.bold.tables.head
return (fontHeader.yMax - fontHeader.yMin) * this.fontScale(fontSize)
} | Gets the line height in pixels for a given font size, using the bold font. | lineHeight | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
top(fontSize) {
let fontHeader = this.config.fonts.bold.tables.head
return fontHeader.yMax * this.fontScale(fontSize)
} | Gets the height in pixels of the top of the font, relative to the baseline, using the bold font. | top | javascript | ritzyed/ritzy | src/core/TextFontMetrics.js | https://github.com/ritzyed/ritzy/blob/master/src/core/TextFontMetrics.js | Apache-2.0 |
function writeText(chunks) {
let text = ''
if(!chunks) {
chunks = []
}
chunks.forEach(c => {
text += c.text
})
return text
} | Writes chunks of rich text into a plain text. The implementation is simple: just strip any style
information from the rich text.
@param {Array} chunks The rich text chunks to write. | writeText | javascript | ritzyed/ritzy | src/core/textwriter.js | https://github.com/ritzyed/ritzy/blob/master/src/core/textwriter.js | Apache-2.0 |
function isWhitespace(char) {
return WHITESPACE_REGEX.test(char)
} | Based on https://github.com/timdown/rangy/blob/master/src/modules/rangy-textrange.js#L119 | isWhitespace | javascript | ritzyed/ritzy | src/core/tokenizer.js | https://github.com/ritzyed/ritzy/blob/master/src/core/tokenizer.js | Apache-2.0 |
function tokenizer(chars, wordOptions) {
let word = _.isArray(chars) ? chars.join('') : chars
let result
let tokenRanges = []
// by default if our options include leading spaces but trailing is not specified, turn off trailing
if(wordOptions && wordOptions.includeLeadingSpace && !wordOptions.includeTrailingSp... | Based on https://github.com/timdown/rangy/blob/master/src/modules/rangy-textrange.js#L119 | tokenizer | javascript | ritzyed/ritzy | src/core/tokenizer.js | https://github.com/ritzyed/ritzy/blob/master/src/core/tokenizer.js | Apache-2.0 |
createTokenRange = function(start, end, isWord) {
tokenRanges.push({start: start, end: end, isWord: isWord})
} | Based on https://github.com/timdown/rangy/blob/master/src/modules/rangy-textrange.js#L119 | createTokenRange | javascript | ritzyed/ritzy | src/core/tokenizer.js | https://github.com/ritzyed/ritzy/blob/master/src/core/tokenizer.js | Apache-2.0 |
createTokenRange = function(start, end, isWord) {
tokenRanges.push({start: start, end: end, isWord: isWord})
} | Based on https://github.com/timdown/rangy/blob/master/src/modules/rangy-textrange.js#L119 | createTokenRange | javascript | ritzyed/ritzy | src/core/tokenizer.js | https://github.com/ritzyed/ritzy/blob/master/src/core/tokenizer.js | Apache-2.0 |
constructor() {
this.exportPublicMethods({
getPosition: () => this.getPosition(),
getRemoteCursors: () => this.getRemoteCursors(),
getContents: () => this.getContents(),
getContentsRich: () => this.getContentsRich(),
getContentsHtml: () => this.getContentsHtml(),
getContentsText:... | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | constructor | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
initialize({config, replica}) {
TextFontMetrics.setConfig(config)
this.config = config
this.replica = replica
this.setState({focus: config.initialFocus})
// store re-initialized with new config, reset the cursor model name
// don't bother checking if it is different, remotes will just get the ... | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | initialize | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
onCursorModelUpdate(cursorModelUpdate) {
this.cursorModelUpdate = cursorModelUpdate
this._setRemoteCursorModelName()
this._setRemoteCursorModelState()
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | onCursorModelUpdate | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
replicaInitialized() {
this.setState({loaded: true})
this._flow()
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | replicaInitialized | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
replicaUpdated() {
// TODO can we determine what changed and do a more focused flow via the modifications parameter?
this._flow()
// update local position and selection if any, and remote selections if any
if(this.state.selectionActive) {
this._updateSelection(this.state, updatedState => {
... | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | replicaUpdated | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
focusInput() {
this._delayedCursorBlink(0)
this.setState({focus: true})
this.config.eventEmitter.emit('focus-gained')
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | focusInput | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
inputFocusLost() {
this.setState({focus: false})
this.config.eventEmitter.emit('focus-lost')
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | inputFocusLost | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
setRemoteCursorPosition(remoteCursor) {
let id = remoteCursor._id
// some bug in Swarm.js: sometimes the id is blank if a lot of cursor events have happened quickly in succession
if(!id) return
// TODO use immutable data structure instead, need clone here to avoid mutating the existing state
let rem... | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | setRemoteCursorPosition | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
unsetRemoteCursorPosition(remoteCursor) {
let id = remoteCursor._id
// some bug in Swarm.js: sometimes the id is blank if a lot of cursor events have happened quickly in succession
if(!id) return
// TODO use immutable data structure instead, need clone here to avoid mutating the existing state
let r... | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | unsetRemoteCursorPosition | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
getPosition() {
return {
char: this.state.position,
eolStart: this.state.positionEolStart
}
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | getPosition | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
getRemoteCursors() {
return Object.values(this.state.remoteCursors)
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | getRemoteCursors | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
getContents() {
return this.replica.getTextRange(BASE_CHAR)
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | getContents | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
getContentsRich() {
return this._getContentRich(this.getContents())
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | getContentsRich | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
getContentsHtml() {
return writeHtml(this.getContentsRich())
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | getContentsHtml | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
getContentsText() {
return writeText(this.getContentsRich())
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | getContentsText | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
navigatePageUp() {
// assume for now a page is 10 lines
this._navigateUpDown(-10)
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | navigatePageUp | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
navigatePageDown() {
// assume for now a page is 10 lines
this._navigateUpDown(10)
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | navigatePageDown | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
navigateStartLine() {
if(this._emptyEditor()) {
this._resetPosition()
return
}
let {line} = lineContainingChar(this.state.lines, this.state.position, this.state.positionEolStart)
this._setPosition(line.start, true)
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | navigateStartLine | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
navigateEnd() {
if(this._emptyEditor()) {
this._resetPosition()
return
}
let positionEolStart = false
if(this._lastLine().isEof()) {
positionEolStart = true
}
this._setPosition(this._relativeChar(BASE_CHAR, -1), positionEolStart)
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | navigateEnd | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
navigateEndLine() {
if(this._emptyEditor()) {
this._resetPosition()
return
}
let {line} = lineContainingChar(this.state.lines, this.state.position, this.state.positionEolStart)
let position
let positionEolStart = false
if(line.isEof() || line.chunks.length === 0) {
position = ... | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | navigateEndLine | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
navigateToCoordinates(coordinates) {
let {position, positionEolStart} = this._coordinatesToPosition(coordinates)
// set the position and selection anchor if the user continues the selection later
position = position ? position : BASE_CHAR
this._setPosition(position, positionEolStart)
this.setState... | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | navigateToCoordinates | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
selectionPageUp() {
// assume for now a page is 10 lines
this._selectionUpDown(-10)
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | selectionPageUp | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
selectionPageDown() {
// assume for now a page is 10 lines
this._selectionUpDown(10)
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | selectionPageDown | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
selectionStart() {
this._modifySelection(BASE_CHAR, true)
this.setActiveAttributes()
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | selectionStart | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
selectionStartLine() {
let {line} = lineContainingChar(this.state.lines, this.state.position, this.state.positionEolStart)
this._modifySelection(line.start, true)
this.setActiveAttributes()
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | selectionStartLine | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
selectionEnd() {
let toChar = this._lastLine() && this._lastLine().isEof() ? EOF : this._relativeChar(BASE_CHAR, -1)
this._modifySelection(toChar, toChar === EOF)
this.setActiveAttributes()
} | The EditorStore is the editor's single source of truth for application state and logic related to the editor.
View state updates are provided to the view components in setState callbacks. This uses the Facebook Flux
unidirectional flow idea: actions (from the view and elsewhere) -> dispatcher -> store -> view.
See htt... | selectionEnd | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
selectionEndLine() {
let {line} = lineContainingChar(this.state.lines, this.state.position, this.state.positionEolStart)
let toChar
let positionEolStart = false
if(line.isEof()) {
toChar = this.state.position
positionEolStart = true
} else if (line.isHard()) {
toChar = this._relati... | Google docs behavior (as of 2015-06-22) is:
- line with soft return, select line with space at end
- line with hard return, select line without selecting the hard return (no action on empty lines)
- EOF line, no action
Word 2010 behavior is:
- line with soft return, select line with space at end
- line with hard retur... | selectionEndLine | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
selectionWordLeft() {
let position
let positionEolStart
if(this.state.position === EOF) {
position = this._lastLine().start
positionEolStart = true
} else {
position = this._wordStartRelativeTo(this.state.position)
positionEolStart = !lineContainingChar(this.state.lines, this.sta... | Google docs behavior (as of 2015-06-22) is:
- line with soft return, select line with space at end
- line with hard return, select line without selecting the hard return (no action on empty lines)
- EOF line, no action
Word 2010 behavior is:
- line with soft return, select line with space at end
- line with hard retur... | selectionWordLeft | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
selectionWordRight() {
let position = this._wordEndRelativeTo(this.state.position)
let endOfLine = lineContainingChar(this.state.lines, this.state.position).endOfLine
this._modifySelection(position, !endOfLine)
this.setActiveAttributes()
} | Google docs behavior (as of 2015-06-22) is:
- line with soft return, select line with space at end
- line with hard return, select line without selecting the hard return (no action on empty lines)
- EOF line, no action
Word 2010 behavior is:
- line with soft return, select line with space at end
- line with hard retur... | selectionWordRight | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
selectionAll() {
this._setPosition(BASE_CHAR)
if(this.state.lines.length === 0) {
this._modifySelection(EOF, true)
} else {
let lastChar = this._lastLine() && this._lastLine().isEof() ? EOF : this._lastLine().end
this._modifySelection(lastChar, false)
}
this.setActiveAttributes()
... | Google docs behavior (as of 2015-06-22) is:
- line with soft return, select line with space at end
- line with hard return, select line without selecting the hard return (no action on empty lines)
- EOF line, no action
Word 2010 behavior is:
- line with soft return, select line with space at end
- line with hard retur... | selectionAll | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
selectToCoordinates(coordinates) {
let {position, positionEolStart} = this._coordinatesToPosition(coordinates)
this._modifySelection(position, positionEolStart)
// we do not setAttributes here, this is handled (for performance reasons) when the mouse up event occurs
} | Google docs behavior (as of 2015-06-22) is:
- line with soft return, select line with space at end
- line with hard return, select line without selecting the hard return (no action on empty lines)
- EOF line, no action
Word 2010 behavior is:
- line with soft return, select line with space at end
- line with hard retur... | selectToCoordinates | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
selectWordAtCurrentPosition() {
if(this.state.lines.length === 0
|| lineContainingChar(this.state.lines, this.state.position, true).line.isEof()) {
this._setPosition(this.state.position)
this._modifySelection(EOF, true)
} else {
let word = this._wordRelativeTo(this.state.position)
... | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | selectWordAtCurrentPosition | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
copySelection(copyHandler) {
let selectionChunks = this._getSelectionRich()
if(selectionChunks && selectionChunks.length > 0) {
let copiedText = writeText(selectionChunks)
let copiedHtml = writeHtml(selectionChunks)
copyHandler(copiedText, copiedHtml, selectionChunks)
}
} | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | copySelection | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
getSelection() {
if(!this.state.selectionActive) return null
return this.replica.getTextRange(this.state.selectionLeftChar, this.state.selectionRightChar)
} | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | getSelection | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
getSelectionRich() {
return this._getSelectionRich()
} | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | getSelectionRich | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
getSelectionHtml() {
return writeHtml(this._getSelectionRich())
} | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | getSelectionHtml | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
getSelectionText() {
return writeText(this._getSelectionRich())
} | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | getSelectionText | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
insertChars({value, attributes, atPosition, reflow}) {
return this._insertChars(value, attributes, atPosition, reflow)
} | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | insertChars | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
insertCharsBatch(chunks) {
let firstInsertPosition = this.state.position
let insertPosition = null
chunks.forEach(c => {
insertPosition = this._insertChars(c.text, c.attrs || null, insertPosition, false)
})
this._flow({start: firstInsertPosition, end: insertPosition, action: 'insert'})
} | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | insertCharsBatch | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
eraseCharBack() {
if(this.state.selectionActive) {
this._eraseSelection()
} else if(!charEq(this.state.position, BASE_CHAR)) {
let position = this._relativeChar(this.state.position, -1)
this.replica.rmChars(this.state.position)
this._flow({ start: position, end: this.state.position, acti... | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | eraseCharBack | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
eraseCharForward() {
if(this.state.selectionActive) {
this._eraseSelection()
} else if(!this._cursorAtEnd()) {
let next = this._relativeChar(this.state.position, 1, 'limit')
this.replica.rmChars(next)
this._flow({ start: this.state.position, end: next, action: ACTION_DELETE})
if(th... | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | eraseCharForward | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
eraseWordBack() {
if(this.state.selectionActive) {
this._eraseSelection()
} else {
let position = this.state.position
let start = this._wordStartRelativeTo(position)
let end = position
if(charEq(start, position)) {
// beginning of word, move to the previous word
let... | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | eraseWordBack | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
eraseWordForward() {
if(this.state.selectionActive) {
this._eraseSelection()
} else {
let position = this.state.position
let options
if(isWhitespace(this._relativeChar(position, 1, 'limit').char)) {
options = { includeLeadingSpace: true }
}
let start = position
... | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | eraseWordForward | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
eraseSelection() {
if(this.state.selectionActive) {
this._eraseSelection()
}
} | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | eraseSelection | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
toggleSuperscript() {
this._toggleAttribute(ATTR.SUPERSCRIPT, ATTR.SUBSCRIPT)
} | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | toggleSuperscript | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
toggleSubscript() {
this._toggleAttribute(ATTR.SUBSCRIPT, ATTR.SUPERSCRIPT)
} | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | toggleSubscript | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
setActiveAttributes() {
let attributes
if(this.state.selectionActive) {
// activeAttributes are set by the common selection attributes
let selection = this.getSelection()
attributes = selection.length > 0 ? selection[0].copyOfAttributes() : null
if(attributes && selection.length > 1) {
... | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | setActiveAttributes | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
registerEditorError(error) {
this.setState({error: error})
} | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | registerEditorError | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
dismissEditorError() {
this.setState({error: null})
} | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | dismissEditorError | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_insertChars(value, attributes, atPosition, reflow) {
if(_.isUndefined(reflow)) reflow = true
let position
if(!attributes) {
// use the active attributes if attributes are not set explicitly
attributes = this.state.activeAttributes
}
if(this.state.selectionActive) {
position = th... | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | _insertChars | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_relativeChar(charOrId, relative, wrap) {
return this.replica.getCharRelativeTo(charOrId, relative, wrap)
} | Word selection follows Google Docs and Microsoft Word 2010 behavior of:
- selecting the word that was clicked, and one or more spaces following it
- if clicking at the end of a line with a soft return, the first word on the next line is selected
- if clicking at the end of a line with a hard return, the hard return is ... | _relativeChar | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
reset() {
this.chars = []
this.length = 0
this.pendingChunks = []
this.advance = 0
this.lineAdvance = 0
this.attributes = null
this.lastCharSpace = false
} | Flows the content i.e. wraps the text into multiple lines, splits each line into chunks with the same
attributes, and sets the component state based on the result. This state is then used for rendering the
editor surface during the next render cycle. This should be called after any operation that may change
the content... | reset | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
pushChar(c, fontSize) {
if(!this.attributes) {
this.attributes = c.attributes
}
let charAdvance = TextFontMetrics.advanceXForChars(fontSize, c)
// don't count spaces in the word in the advance, but include it in the line advance
if(c.char === ' ') {
this.last... | Flows the content i.e. wraps the text into multiple lines, splits each line into chunks with the same
attributes, and sets the component state based on the result. This state is then used for rendering the
editor surface during the next render cycle. This should be called after any operation that may change
the content... | pushChar | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
popChar() {
this.length--
return this.chars.pop()
} | Flows the content i.e. wraps the text into multiple lines, splits each line into chunks with the same
attributes, and sets the component state based on the result. This state is then used for rendering the
editor surface during the next render cycle. This should be called after any operation that may change
the content... | popChar | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
pushChunks() {
if(this.length > 0) {
this.pendingChunks.push({
length: this.length,
attributes: this.attributes
})
}
this.attributes = null
this.length = 0
} | Flows the content i.e. wraps the text into multiple lines, splits each line into chunks with the same
attributes, and sets the component state based on the result. This state is then used for rendering the
editor surface during the next render cycle. This should be called after any operation that may change
the content... | pushChunks | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
reset() {
this.chars = []
this.chunks = []
this.advance = 0
this.start = null
this.end = null
} | Flows the content i.e. wraps the text into multiple lines, splits each line into chunks with the same
attributes, and sets the component state based on the result. This state is then used for rendering the
editor surface during the next render cycle. This should be called after any operation that may change
the content... | reset | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
pushWord(word) {
pushArray(this.chars, word.chars)
let lastChunk
if(this.chunks.length > 0) {
lastChunk = this.chunks[this.chunks.length - 1]
// if the last chunk in the line matches attributes with the first word chunk, join them to minimize chunks
if(attributesEq... | Flows the content i.e. wraps the text into multiple lines, splits each line into chunks with the same
attributes, and sets the component state based on the result. This state is then used for rendering the
editor surface during the next render cycle. This should be called after any operation that may change
the content... | pushWord | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
pushNewline(c) {
invariant(c.char === '\n', 'pushNewline can only be called with a newline char.')
this.chars.push(c)
this.end = c
} | Flows the content i.e. wraps the text into multiple lines, splits each line into chunks with the same
attributes, and sets the component state based on the result. This state is then used for rendering the
editor surface during the next render cycle. This should be called after any operation that may change
the content... | pushNewline | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
pushEof() {
this.end = EOF
} | Flows the content i.e. wraps the text into multiple lines, splits each line into chunks with the same
attributes, and sets the component state based on the result. This state is then used for rendering the
editor surface during the next render cycle. This should be called after any operation that may change
the content... | pushEof | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
pushLine = (line) => {
if(line.end) {
let l = new Line(line.chars, line.chunks, line.start, line.end, line.advance)
lines.push(l)
if(FLOW_DEBUG) {
console.debug(`PUSHED LINE (index=${lines.length - 1}): ${l.toString()}`)
}
newLine = true
}
line.reset()... | Flows the content i.e. wraps the text into multiple lines, splits each line into chunks with the same
attributes, and sets the component state based on the result. This state is then used for rendering the
editor surface during the next render cycle. This should be called after any operation that may change
the content... | pushLine | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
pushLine = (line) => {
if(line.end) {
let l = new Line(line.chars, line.chunks, line.start, line.end, line.advance)
lines.push(l)
if(FLOW_DEBUG) {
console.debug(`PUSHED LINE (index=${lines.length - 1}): ${l.toString()}`)
}
newLine = true
}
line.reset()... | Flows the content i.e. wraps the text into multiple lines, splits each line into chunks with the same
attributes, and sets the component state based on the result. This state is then used for rendering the
editor surface during the next render cycle. This should be called after any operation that may change
the content... | pushLine | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_setRemoteCursorModelName() {
if(!this.cursorModelUpdate) return
let updatedModel = {
name: this.config.userName,
ms: Date.now()
}
this.cursorModelUpdate(updatedModel)
} | Flows the content i.e. wraps the text into multiple lines, splits each line into chunks with the same
attributes, and sets the component state based on the result. This state is then used for rendering the
editor surface during the next render cycle. This should be called after any operation that may change
the content... | _setRemoteCursorModelName | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_setRemoteCursorModelState() {
if(!this.cursorModelUpdate) return
let updatedModel = {
state: {
position: this.state.position.id,
positionEolStart: this.state.positionEolStart,
selectionActive: this.state.selectionActive,
selectionLeftChar: this.state.selectionActive ? cha... | Flows the content i.e. wraps the text into multiple lines, splits each line into chunks with the same
attributes, and sets the component state based on the result. This state is then used for rendering the
editor surface during the next render cycle. This should be called after any operation that may change
the content... | _setRemoteCursorModelState | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_setPosition(position, positionEolStart, resetUpDown) {
if(_.isUndefined(positionEolStart)) positionEolStart = this.state.positionEolStart
if(_.isUndefined(resetUpDown)) resetUpDown = true
//console.debug('position', position, 'positionEolStart', positionEolStart, 'resetUpDown', resetUpDown)
let curre... | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | _setPosition | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_delayedCursorBlink(timeout) {
if(_.isUndefined(timeout)) timeout = 1000
this.setState({cursorMotion: true})
// after timeout, reset the cursor blink, clear any previous resets to avoid unnecessary state changes
if(this.cursorMotionTimeout) {
clearTimeout(this.cursorMotionTimeout)
}
this... | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | _delayedCursorBlink | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_delayedRemoteCursorNameReveal(id, timeout) {
if(_.isUndefined(timeout)) timeout = 2000
// TODO use immutable data structure instead, need to create a new Set here to avoid mutating the existing state
let remoteNameReveal = new Set(this.state.remoteNameReveal)
remoteNameReveal.add(id)
this.setState... | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | _delayedRemoteCursorNameReveal | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_lastLine() {
return this.state.lines[this.state.lines.length - 1]
} | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | _lastLine | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_emptyEditor() {
return this.state.lines.length === 0
&& (this.state.position === EOF || charEq(this.state.position, BASE_CHAR))
} | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | _emptyEditor | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_cursorAtEnd() {
return this._emptyEditor()
|| charEq(this.state.position, this._lastLine().end)
|| (this._lastLine().isEof() && charEq(this.state.position, this._lastLine().start))
} | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | _cursorAtEnd | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_getContentRich(chars) {
let contentChunks = []
let currentChunk = {
chars: [],
attributes: null,
reset() {
this.chars = []
this.attributes = null
},
pushChar(c) {
if(!this.attributes) {
this.attributes = c.attributes
}
// push n... | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | _getContentRich | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
reset() {
this.chars = []
this.attributes = null
} | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | reset | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
pushChar(c) {
if(!this.attributes) {
this.attributes = c.attributes
}
// push newlines as separate chunks for ease of parsing paragraphs and breaks from chunks
let isNewline = c.char === '\n'
if(isNewline) {
// previous chunk
this.pushChunk()
... | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | pushChar | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
pushChunk() {
if(this.chars.length > 0) {
contentChunks.push({
text: this.chars.join(''),
attrs: this.attributes
})
}
this.reset()
} | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | pushChunk | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
processChar = (c) => {
if (!attributesEqual(currentChunk.attributes, c.attributes)) {
currentChunk.pushChunk()
}
currentChunk.pushChar(c, this)
} | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | processChar | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
processChar = (c) => {
if (!attributesEqual(currentChunk.attributes, c.attributes)) {
currentChunk.pushChunk()
}
currentChunk.pushChar(c, this)
} | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | processChar | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_getSelectionRich() {
let selectionChars = this.state.selectionActive ?
this.replica.getTextRange(this.state.selectionLeftChar, this.state.selectionRightChar) :
[]
return this._getContentRich(selectionChars)
} | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | _getSelectionRich | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_modifySelection(toChar, positionEolStart, resetUpDown) {
if(!toChar) return
if(_.isUndefined(resetUpDown)) resetUpDown = true
if(this.cursorMotionTimeout) {
clearTimeout(this.cursorMotionTimeout)
}
let previousSelection = {
selectionActive: this.state.selectionActive,
selectionL... | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | _modifySelection | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_updateSelection(state, onUpdate) {
let possibleSelectionLeftChar = this._relativeChar(state.selectionLeftChar, 0)
let possibleSelectionRightChar = this._relativeChar(state.selectionRightChar, 0)
if(!charEq(state.selectionLeftChar, possibleSelectionLeftChar)
|| !charEq(state.selectionRightChar, possi... | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | _updateSelection | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_updateRemoteCursorSelectionsLocally() {
Object.values(this.state.remoteCursors).filter(c => c.state.selectionActive).forEach(remoteCursor => {
this._updateSelection(remoteCursor.state, updatedState => {
// we are updating the remote state here directly, a bit messy but we'll get the real update from ... | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | _updateRemoteCursorSelectionsLocally | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
_charPositionRelativeToIndex(charIndex, textChars) {
if(charIndex === 0) {
return this._relativeChar(textChars[0], -1)
} else {
return textChars[charIndex - 1]
}
} | Sets the character and cursor position within the text. The position is relative to an existing
character given by its replica id. The cursor position is calculated based on the character
position. This is generally straightforward except when the character position is the last
character of a line. In this situation, t... | _charPositionRelativeToIndex | javascript | ritzyed/ritzy | src/flux/EditorStore.js | https://github.com/ritzyed/ritzy/blob/master/src/flux/EditorStore.js | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.