Coder Social home page Coder Social logo

Spell Check about rocket.chat.electron HOT 5 CLOSED

rocketchat avatar rocketchat commented on May 11, 2024
Spell Check

from rocket.chat.electron.

Comments (5)

rodrigok avatar rodrigok commented on May 11, 2024

Now we have spell checker 😄

from rocket.chat.electron.

geekgonecrazy avatar geekgonecrazy commented on May 11, 2024

@rodrigok is this still osx only or is windows support there? Cause i'm not seeing this in the v1.0.0 release on windows either 😦

from rocket.chat.electron.

rodrigok avatar rodrigok commented on May 11, 2024

The spell checker code is working, but I can't compile the dictionary for windows, so, you can use on windows now.
Maybe you can try to compile this module

from rocket.chat.electron.

crimsoncor avatar crimsoncor commented on May 11, 2024

So the currently implement of spell checking leaves some things to be desired. It seems to be based off the suggestion here electron/electron#942, but that implementation is flawed because it builds the context menu at the time of the word being checked, not at right-click time which leads to weird graphical inconsistencies. For example, try misspelling a word and then right-clicking somewhere outside the current text area: you'll see the list of possible replacements but selecting an option does nothing.

Replacing the current implementation in preload.js with the below code yields much better results for me.

var remote = require('remote');
var spellchecker = require('spellchecker')
var Menu = remote.require('menu');

var template = [
{
  label: "Undo",
  click: function(item, window) {
    remote.getCurrentWebContents().undo();
  }
},
{
  label: "Redo",
  click: function(item, window) {
    remote.getCurrentWebContents().redo();
  }
},
{
  type: 'separator'
},
{
  label: "Cut",
  click: function(item, window) {
    remote.getCurrentWebContents().cut();
  }
},
{
  label: "Copy",
  click: function(item, window) {
    remote.getCurrentWebContents().copy();
  }
},
{
  label: "Paste",
  click: function(item, window) {
    remote.getCurrentWebContents().paste();
  }
},
{
  type: 'separator'
},
{
  label: "Select All",
  click: function(item, window) {
    remote.getCurrentWebContents().selectAll();
  }
}];

require('web-frame').setSpellCheckProvider((localStorage.getItem('userLanguage') || "en-US"),
                                            false, {
  spellCheck: function(text) {
    return !(spellchecker.isMisspelled(text));
  }
});

window.addEventListener('contextmenu', function(event) {
  switch(event.target.nodeName) {
    case 'TEXTAREA':
      var value = event.target.value;
      var cursor = event.target.selectionStart;
      var strLength = value.length;
      event.preventDefault();
      if (cursor == strLength || value.charAt(cursor) == " ") {
        var menu = Menu.buildFromTemplate(template);
        menu.popup(remote.getCurrentWindow());
      }
      else {
        var end = value.indexOf(" ", cursor);
        end = end == -1 ? strLength : end;
        var start = value.lastIndexOf(" ", cursor) + 1;
        var text = value.substring(start, end);
        var bad = spellchecker.isMisspelled(text);
        var newTemplate = template.slice();
        if (bad) {
          var replacements = spellchecker.getCorrectionsForMisspelling(text);
          var num = replacements.length ? replacements.length : 0;
          var maxItems = num > 7 ? 7 : num;
          var items = [];
          for (var i = 0; i < maxItems; i++) {
            var item = replacements[i];
            items.push({
              label: item,
              click : function(menuItem, window) {
                remote.getCurrentWebContents().replaceMisspelling(menuItem.label);
              }
            });
          }
          if (maxItems > 0) {
            newTemplate.push({
              type: 'separator'
            });
            newTemplate.push({
              label: "Spelling suggestions",
              submenu: items
            });
          }
        }
        var menu = Menu.buildFromTemplate(newTemplate);
        menu.popup(remote.getCurrentWindow());
      }
      break;
    default:
      var menu = Menu.buildFromTemplate(template);
      menu.popup(remote.getCurrentWindow());
      break;
  }

}, false);

from rocket.chat.electron.

rodrigok avatar rodrigok commented on May 11, 2024

@crimsoncor see #121 and #122

Thanks

from rocket.chat.electron.

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.