Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement separateGroups option #183

Merged
merged 3 commits into from Jan 25, 2018
Merged

Implement separateGroups option #183

merged 3 commits into from Jan 25, 2018

Conversation

julkue
Copy link
Owner

@julkue julkue commented Jan 14, 2018

According to #132
Follow-up from #136

@Mottie I've now restored your original PR. Since then, I've added new ESLint config properties that caused it to fail, since the wrapMatches method is now too complex. Therfore I added ignore comments temporarily. Do you have a suggestion of making this for easy to read and understand?

Is this a replacement of the ignoreGroups option? Could you please describe the change in a short explanation for the docs?

@Mottie
Copy link
Collaborator

Mottie commented Jan 19, 2018

I've made the necessary fixes, but I can't get the tests to complete; and it always stops at the same point...

basic mark with diacritics for Vietnamese
    √ should treat normal and diacritic characters equally
18 01 2018 22:20:10.383:WARN [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Disconnected (1 times), because no message in 60000 ms.
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
  Disconnected, because no message in 60000 ms.

PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 20 of 162 DISCONNECTED (1 min 6.118 secs / 6.125 secs)

----------|----------|----------|----------|----------|----------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
----------|----------|----------|----------|----------|----------------|
All files |      100 |      100 |      100 |      100 |                |
----------|----------|----------|----------|----------|----------------|

Should I go ahead and push the changes? I'm sure the separate groups tests will still pass, but we can't be sure until I push the code here.

@julkue
Copy link
Owner Author

julkue commented Jan 19, 2018

@Mottie Yes, please push it. We then see why this error appears.

@Mottie
Copy link
Collaborator

Mottie commented Jan 19, 2018

Grrr, eslint isn't showing me that the complexity level issue.

@julkue
Copy link
Owner Author

julkue commented Jan 19, 2018

@Mottie I've successfully ran the build on the master branch with the same modules like on groups-restore. So I was sure that it's an issue of the changes. Then I played around with the test around the last successful one and gotcha: basic mark with duplicated contexts is failing. I've extracted the test into manual.html. Now opening this file will freeze the tab. That's why there is no response from PhantomJS within 60sec.

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>mark.js manual test (dev purposes)</title>
  <style>
    mark {
      background: yellow;
    }
  </style>
</head>
<body>
<div id="context"></div>
<script src="../node_modules/jquery/dist/jquery.min.js"></script>
<script src="../dist/mark.js"></script>
<script>
  const $ctx = $("#context");
  $ctx.load("fixtures/basic/duplicate-context.html", function() {
    var $ctx1 = $ctx.find('.basic-duplicate-context > div:first-child');
    var $ctx2 = $ctx.find('.basic-duplicate-context > div:last-child');
    var ctx1Called = 0;
    var ctx2Called = 0;
    function done(){
      console.log('DONE');
    }
    new Mark([$ctx1[0], $ctx1[0]]).mark('test', {
      'diacritics': false,
      'separateWordSearch': false,
      'filter': function(){
        ctx1Called++;
        // return false. Otherwise matches would become wrapped and no
        // further matches would be found. Therefore no further filter
        // calls would be done
        return false;
      },
      'done': function() {
        new Mark([$ctx2[0], $ctx2.find('span')[0]]).mark('test', {
          'filter': function(){
            ctx2Called++;
            // return false. Otherwise matches would become wrapped
            // and no further matches would be found. Therefore no
            // further filter calls would be done
            return false;
          },
          'done': function(){
            done();
          }
        });
      }
    });
  });
</script>
</body>
</html>

@Mottie
Copy link
Collaborator

Mottie commented Jan 19, 2018

Is nothing highlighted in that example? I ran it on the master branch and nada...

https://jsfiddle.net/j0jdyama/37/

Edit: I mean, I don't understand what it means that the matches will become wrapped. It works fine if I return true from the filter callback function.

@julkue
Copy link
Owner Author

julkue commented Jan 19, 2018

@Mottie No highlights are expected in this test. The filter callback function is always returning false. The test just counts how many times the filter callback is called, to determine if duplicated contexts will be ignored.

However, if I open the above mentioned manual.html page in the browser I'm getting a toolbar if I want to terminate the script and then I get:

topic

So the browser freezes, and this is the issue I was talking about, not that no highlights are done.

@julkue
Copy link
Owner Author

julkue commented Jan 20, 2018

@Mottie Are you done from your side?

@Mottie
Copy link
Collaborator

Mottie commented Jan 20, 2018

Yes 😸

@julkue
Copy link
Owner Author

julkue commented Jan 21, 2018

Can you please also answer my questions?

Is this a replacement of the ignoreGroups option? Could you please describe the change in a short explanation for the docs?

@Mottie
Copy link
Collaborator

Mottie commented Jan 21, 2018

Is this a replacement of the ignoreGroups option?

The separateGroups option does replace the ignoreGroups; to duplicate the behavior of ignoreGroups you can use the each callback. @DrParanoia did request that the each callback include a group counter, but that wasn't included because the each callback has a specific definition internally; sorry I guess I never answered his question. And I forgot to ask you (@julmot) about it. I think it would indeed be a nice addition but it would require altering the initial definition of the eachCb function.

describe the change in a short explanation for the docs

The separateGroup option, included with the markRegExp function, allows the marking of each group within a regular expression separately. For example, using /(hello): ([\w+.]+)/gi would highlight hello and any text following the colon separately; but only if it matches the full regular expression - see this demo.

@julkue
Copy link
Owner Author

julkue commented Jan 21, 2018

@Mottie As this replaces the ignoreGroups it needs to be removed and the existing tests need to be adjusted in order to cover the existing feature.

@Mottie
Copy link
Collaborator

Mottie commented Jan 21, 2018

I mean the ignoreGroups option still exists. If you set the separateGroups option, it overrides ignoreGroups. Are you saying we're going to completely do away with the ignoreGroups option?

@julkue
Copy link
Owner Author

julkue commented Jan 21, 2018

@Mottie If you can achieve the same effect with plain separateGroups, from my point of view ignoreGroups is redunant and needs to be removed. However, tests of ignoreGroups shouldn't be removed, instead only be adjusted to work with separateGroups.

This will then be available with the next major release.

@Mottie
Copy link
Collaborator

Mottie commented Jan 22, 2018

@Mottie If you can achieve the same effect with plain separateGroups

As it stands now, you can't achieve the same effect easily. You would need to include the match index in the filter, and even the each (as a nicety), callback that was mentioned before. And that would require modifying the main filter and each callback methods. We haven't discussed making this change, so how do you feel about that?

@Mottie
Copy link
Collaborator

Mottie commented Jan 25, 2018

Ping @julmot... what should I do?

@julkue
Copy link
Owner Author

julkue commented Jan 25, 2018

@Mottie Sorry for not answering earlier. As far as I understand it would be enough to modify the parameters of the each and filter callbacks. Since this would mean that it's a backward incompatible change it would require a major version. Since v9.0.0 is already in progress with the diacritics feature, I'd suggest to merge this PR and implement the remaining callback modifications once the diacritics thing is completed. Do you agree?

@julkue julkue added this to the 9.0.0 milestone Jan 25, 2018
@Mottie
Copy link
Collaborator

Mottie commented Jan 25, 2018

Yes, we can remove the ignoreGroups completely in v9.

@julkue julkue merged commit 396d618 into master Jan 25, 2018
@julkue julkue deleted the groups-restore branch January 25, 2018 17:48
@julkue
Copy link
Owner Author

julkue commented Nov 7, 2018

@Mottie I have planned to release the v9 release as it is with the following features:

  • Synonyms as arrays
  • Separate groups in RegExp

Therefore, my question to you is what we need to do in order to release this? We should normalize ignoreGroups and separateGroups as it's not easily to understand what they do. We shouldn't have two options that can't be used together.

@Mottie
Copy link
Collaborator

Mottie commented Nov 7, 2018

Oh, I thought the plan was to remove ignoreGroups completely; and I'm not sure what you mean by normalizing ignoreGroups and separateGroups.

@julkue
Copy link
Owner Author

julkue commented Nov 7, 2018

@Mottie So, as far as I understand, the separateGroups option replaces the ignoreGroups option if it's set to true -- because you can not ignore it and enabling highlighting of groups individually together.

Therefore, it's safe to drop ignoreGroups in a new major release?

@Mottie
Copy link
Collaborator

Mottie commented Nov 7, 2018

Yes! 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants