Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5964697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:28:48+00:00 2026-05-22T19:28:48+00:00

I am using NSTextView for the user to type their response. I have turned

  • 0

I am using NSTextView for the user to type their response. I have turned on continuous spell check and the incorrect words have a red line under them. I have a shared SpellChecker which I am using. But I want the user to do a right click and correct the spelling. I have the following questions –

  1. In Text edit, as soon as you do a right click, it highlights the word, how can I achieve the same ?. I am planning to get the selectedrange and pass it to the spellchecker.

  2. Once the spellcheck suggestions are added to the context menu, it still shows up when I go to the next word, so should I always clear the context menu before adding any new item ?.

  3. I am using Monobjc, and when I execute the following code, I get an exception –

    var t = Menu.ItemArray;

    foreach(var s in t)

    {

    var menuItem = s.CastAs<NSMenuItem>(); //exception

    }

I am basically try to get individual NSMenuItem to check if it spelling suggestions or something else.

EDIT – Added stacktrace

System.InvalidCastException: Cannot cast from source type to destination type.
  at example.test.MacOS.UI.HTML.ESView.MenuForEvent (Monobjc.Cocoa.NSEvent theEvent) [0x00000] in <filename unknown>:0 
  at Monobjc.Dynamic.Proxies.example.test.MacOS.UI.HTML.ESView.MenuForEvent_Monobjc_Cocoa_NSEvent (IntPtr receiver, IntPtr selector, IntPtr ) [0x00000] in <filename unknown>:0 
  at (wrapper native-to-managed) Monobjc.Dynamic.Proxies.example.test.MacOS.UI.HTML.ESView:MenuForEvent_Monobjc_Cocoa_NSEvent (intptr,intptr,intptr)
  at (wrapper managed-to-native) E5EEC20A:pinvoke (intptr,intptr,intptr)
  at E5EEC20A.objc_msgSendSuper (IntPtr receiver, IntPtr selector, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at Monobjc.Bridge.Generators.DynamicMessagingGenerator.SendMessage (System.String message, IntPtr receiver, IntPtr selector, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at Monobjc.ObjectiveCRuntime.SendMessageSuper (IManagedWrapper receiver, Monobjc.Class cls, System.String selector, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at Monobjc.Id.SendMessageSuper (Monobjc.Class cls, System.String selector, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at example.test.MacOS.UI.App.Application.SendEvent (Monobjc.Cocoa.NSEvent theEvent) [0x00000] in <filename unknown>:0 
  at Monobjc.Dynamic.Proxies.example.test.MacOS.UI.App.Application.SendEvent_Monobjc_Cocoa_NSEvent (IntPtr receiver, IntPtr selector, IntPtr ) [0x00000] in <filename unknown>:0 
  at (wrapper native-to-managed) Monobjc.Dynamic.Proxies.example.test.MacOS.UI.App.Application:SendEvent_Monobjc_Cocoa_NSEvent (intptr,intptr,intptr)
  at (wrapper managed-to-native) Monobjc.ObjectiveCRuntime:objc_msgSend (intptr,intptr)
  at Monobjc.ObjectiveCRuntime.SendMessage (IManagedWrapper receiver, System.String selector) [0x00000] in <filename unknown>:0 
  at Monobjc.Cocoa.NSApplication.Run () [0x00000] in <filename unknown>:0 
  at example.test.MacOS.UI.App.Application.RunApplication () [0x00000] in <filename unknown>:0 
  at example.test.MacOS.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 

EDIT – Step 3

Question 3 worked based on Laurent’s suggestion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:28:49+00:00Added an answer on May 22, 2026 at 7:28 pm

    For point 1)

    • NSTextView.SelectedRange returns the first selected range. If no text is selected the range’s length is 0 and the range’s location is the index of the character where the cursor lies.
    • Then, get a reference to the string context (NSTextView.TextStorage.String) and search for whitespace before and after the cursor location. You will get the range for the word to select.
    • Use NSTextView.SelectedRange to specify the new selection range.

    For point 2)

    You have a total control over the Menu instance returned when a right-click is done. So if you add items to it, you have to remove them by yourself.

    For point 3)

    It looks like a bug. As mention in the comment, use the NumberOfItems and ItemAtIndexmethods within an indexed loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a subclassed NSTextView that I am manipulating in a separate thread (using
I have an NSTextField that I would like to enable as-you-type spell checking. When
I have NSTextView and need rounded corners for the same. Hence i tried using
I have NSTextView that i add text to using def puts(val) storage = @output.textStorage
Using online interfaces to a version control system is a nice way to have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C#, I need a class called User that has a username, password, active
I am using the following code to perform drag operation on NSTextView object. -
I am creating an application using NSDocument. MyDocument.xib just has an NSTextView in an
I have a basic NSTextView with rich text and graphics enabled (in IB). What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.