Code Monkey home page Code Monkey logo

Comments (3)

cdfmlr avatar cdfmlr commented on May 18, 2024

Humm, self help:🤪

I just peeked the code and tried something in a playground. I guess I can say that this issue is caused by replaceCharacters with a wrong range.

import AppKit
import Foundation
import PlaygroundSupport

var textStorage: NSTextStorage = NSTextStorage()

textStorage.replaceCharacters(
    in: NSRange(location: 0, length: textStorage.string.count),
    with: "hello,世界!😀")

textStorage.string.count
textStorage.length

let range = NSRange(location: 0, length: textStorage.string.count)
//let range = NSRange(location: 0, length: textStorage.length)

textStorage.replaceCharacters(in: range, with: "")

let length = textStorage.string.count

image-20200702113610189

As we can see, different from string.count, a utf-16 char in NSTextStorage is not length one.

Replace textStorage.string.count with a textStorage.length helps a lot:

image-20200702114557081

This is not a big problem, I am now working on this, PR to solve it soon.

from boop.

IvanMathy avatar IvanMathy commented on May 18, 2024

Oh wow, this explains a lot of issues I've been seeing lately but could not pinpoint... Thank you so much for taking the time to document it, research it, and fix it! It would have taken me a while to realize all those were linked, and even more so to figure out how to address it.

I'll test your changes and merge it all in. Thank you again!

from boop.

IvanMathy avatar IvanMathy commented on May 18, 2024

Merged, thanks for the help!

from boop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.