mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Pass character codes around in TextUtils
Previously the character codes were looked up for each type of character pair.
This commit is contained in:
parent
d1fcfabf0b
commit
dc824485aa
@ -1,56 +1,61 @@
|
|||||||
isHighSurrogate = (string, index) ->
|
isHighSurrogate = (charCode) ->
|
||||||
0xD800 <= string.charCodeAt(index) <= 0xDBFF
|
0xD800 <= charCode <= 0xDBFF
|
||||||
|
|
||||||
isLowSurrogate = (string, index) ->
|
isLowSurrogate = (charCode) ->
|
||||||
0xDC00 <= string.charCodeAt(index) <= 0xDFFF
|
0xDC00 <= charCode <= 0xDFFF
|
||||||
|
|
||||||
isVariationSelector = (string, index) ->
|
isVariationSelector = (charCode) ->
|
||||||
0xFE00 <= string.charCodeAt(index) <= 0xFE0F
|
0xFE00 <= charCode <= 0xFE0F
|
||||||
|
|
||||||
isCombiningCharacter = (string, index) ->
|
isCombiningCharacter = (charCode) ->
|
||||||
0x0300 <= string.charCodeAt(index) <= 0x036F or
|
0x0300 <= charCode <= 0x036F or
|
||||||
0x1AB0 <= string.charCodeAt(index) <= 0x1AFF or
|
0x1AB0 <= charCode <= 0x1AFF or
|
||||||
0x1DC0 <= string.charCodeAt(index) <= 0x1DFF or
|
0x1DC0 <= charCode <= 0x1DFF or
|
||||||
0x20D0 <= string.charCodeAt(index) <= 0x20FF or
|
0x20D0 <= charCode <= 0x20FF or
|
||||||
0xFE20 <= string.charCodeAt(index) <= 0xFE2F
|
0xFE20 <= charCode <= 0xFE2F
|
||||||
|
|
||||||
# Is the character at the given index the start of a high/low surrogate pair?
|
# Are the given character codes a high/low surrogate pair?
|
||||||
#
|
#
|
||||||
# * `string` The {String} to check for a surrogate pair.
|
# * `charCodeA` The first character code {Number}.
|
||||||
# * `index` The {Number} index to look for a surrogate pair at.
|
# * `charCode2` The second character code {Number}.
|
||||||
#
|
#
|
||||||
# Return a {Boolean}.
|
# Return a {Boolean}.
|
||||||
isSurrogatePair = (string, index=0) ->
|
isSurrogatePair = (charCodeA, charCodeB) ->
|
||||||
isHighSurrogate(string, index) and isLowSurrogate(string, index + 1)
|
isHighSurrogate(charCodeA) and isLowSurrogate(charCodeB)
|
||||||
|
|
||||||
# Is the character at the given index the start of a variation sequence?
|
# Are the given character codes a variation sequence?
|
||||||
#
|
#
|
||||||
# * `string` The {String} to check for a variation sequence.
|
# * `charCodeA` The first character code {Number}.
|
||||||
# * `index` The {Number} index to look for a variation sequence at.
|
# * `charCode2` The second character code {Number}.
|
||||||
#
|
#
|
||||||
# Return a {Boolean}.
|
# Return a {Boolean}.
|
||||||
isVariationSequence = (string, index=0) ->
|
isVariationSequence = (charCodeA, charCodeB) ->
|
||||||
not isVariationSelector(string, index) and isVariationSelector(string, index + 1)
|
not isVariationSelector(charCodeA) and isVariationSelector(charCodeB)
|
||||||
|
|
||||||
# Is the character at the given index the start of a combined character pair?
|
# Are the given character codes a combined character pair?
|
||||||
#
|
#
|
||||||
# * `string` The {String} to check for a combined character.
|
# * `charCodeA` The first character code {Number}.
|
||||||
# * `index` The {Number} index to look for a variation sequence at.
|
# * `charCode2` The second character code {Number}.
|
||||||
#
|
#
|
||||||
# Return a {Boolean}.
|
# Return a {Boolean}.
|
||||||
isCombinedCharacter = (string, index=0) ->
|
isCombinedCharacter = (charCodeA, charCodeB) ->
|
||||||
not isCombiningCharacter(string, index) and isCombiningCharacter(string, index + 1)
|
not isCombiningCharacter(charCodeA) and isCombiningCharacter(charCodeB)
|
||||||
|
|
||||||
# Is the character at the given index the start of high/low surrogate pair
|
# Is the character at the given index the start of high/low surrogate pair
|
||||||
# a variation sequence, or a combined character?
|
# a variation sequence, or a combined character?
|
||||||
#
|
#
|
||||||
# * `string` The {String} to check for a surrogate pair, variation sequence,
|
# * `string` The {String} to check for a surrogate pair, variation sequence,
|
||||||
# or combined character.
|
# or combined character.
|
||||||
# * `index` The {Number} index to look for a surrogate pair at.
|
# * `index` The {Number} index to look for a surrogate pair, variation
|
||||||
|
# sequence, or combined character.
|
||||||
#
|
#
|
||||||
# Return a {Boolean}.
|
# Return a {Boolean}.
|
||||||
isPairedCharacter = (string, index=0) ->
|
isPairedCharacter = (string, index=0) ->
|
||||||
isSurrogatePair(string, index) or isVariationSequence(string, index) or isCombinedCharacter(string, index)
|
charCodeA = string.charCodeAt(index)
|
||||||
|
charCodeB = string.charCodeAt(index + 1)
|
||||||
|
isSurrogatePair(charCodeA, charCodeB) or
|
||||||
|
isVariationSequence(charCodeA, charCodeB) or
|
||||||
|
isCombinedCharacter(charCodeA, charCodeB)
|
||||||
|
|
||||||
# Does the given string contain at least surrogate pair, variation sequence,
|
# Does the given string contain at least surrogate pair, variation sequence,
|
||||||
# or combined character?
|
# or combined character?
|
||||||
|
@ -402,6 +402,8 @@ class Workspace extends Model
|
|||||||
item ?= opener(atom.project.resolve(uri), options) for opener in @getOpeners() when !item
|
item ?= opener(atom.project.resolve(uri), options) for opener in @getOpeners() when !item
|
||||||
item ?= atom.project.open(uri, options)
|
item ?= atom.project.open(uri, options)
|
||||||
|
|
||||||
|
console.profile('open')
|
||||||
|
|
||||||
Q(item)
|
Q(item)
|
||||||
.then (item) =>
|
.then (item) =>
|
||||||
if not pane
|
if not pane
|
||||||
@ -413,6 +415,7 @@ class Workspace extends Model
|
|||||||
index = pane.getActiveItemIndex()
|
index = pane.getActiveItemIndex()
|
||||||
@emit "uri-opened"
|
@emit "uri-opened"
|
||||||
@emitter.emit 'did-open', {uri, pane, item, index}
|
@emitter.emit 'did-open', {uri, pane, item, index}
|
||||||
|
console.profileEnd('open')
|
||||||
item
|
item
|
||||||
.catch (error) ->
|
.catch (error) ->
|
||||||
console.error(error.stack ? error)
|
console.error(error.stack ? error)
|
||||||
|
Loading…
Reference in New Issue
Block a user