Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 6b555e6

Browse files
authored
Merge pull request #294 from atom/aw/has-astral
TextBuffer::hasAstral()
2 parents 7414d90 + 03d835b commit 6b555e6

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"mkdirp": "^0.5.1",
5555
"pathwatcher": "8.0.1",
5656
"serializable": "^1.0.3",
57-
"superstring": "^2.2.20",
57+
"superstring": "2.3.0",
5858
"underscore-plus": "^1.0.0"
5959
},
6060
"standard": {

spec/text-buffer-spec.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,6 +2609,13 @@ describe "TextBuffer", ->
26092609
buffer.setText('\n')
26102610
expect(buffer.isEmpty()).toBeFalsy()
26112611

2612+
describe "::hasAstral()", ->
2613+
it "returns true for buffers containing surrogate pairs", ->
2614+
expect(new TextBuffer('hooray 😄').hasAstral()).toBeTruthy()
2615+
2616+
it "returns false for buffers that do not contain surrogate pairs", ->
2617+
expect(new TextBuffer('nope').hasAstral()).toBeFalsy()
2618+
26122619
describe "::onWillChange(callback)", ->
26132620
it "notifies observers before a transaction, an undo or a redo", ->
26142621
changeCount = 0

src/text-buffer.coffee

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class TextBuffer
170170
@nextMarkerId = 1
171171
@outstandingSaveCount = 0
172172
@loadCount = 0
173+
@cachedHasAstral = null
173174
@_emittedWillChangeEvent = false
174175

175176
@setEncoding(params?.encoding)
@@ -728,6 +729,17 @@ class TextBuffer
728729
return row unless @isRowBlank(row)
729730
null
730731

732+
# Extended: Return true if the buffer contains any astral-plane Unicode characters that
733+
# are encoded as surrogate pairs.
734+
#
735+
# Returns a {Boolean}.
736+
hasAstral: ->
737+
if @cachedHasAstral isnt null
738+
@cachedHasAstral
739+
else
740+
@cachedHasAstral = @buffer.hasAstral()
741+
@cachedHasAstral
742+
731743
###
732744
Section: Mutating Text
733745
###
@@ -2066,6 +2078,7 @@ class TextBuffer
20662078
@_emittedWillChangeEvent = true
20672079

20682080
emitDidChangeTextEvent: ->
2081+
@cachedHasAstral = null
20692082
if @transactCallDepth is 0
20702083
if @changesSinceLastDidChangeTextEvent.length > 0
20712084
compactedChanges = patchFromChanges(@changesSinceLastDidChangeTextEvent).getChanges()

0 commit comments

Comments
 (0)