StyledPopup icon indicating copy to clipboard operation
StyledPopup copied to clipboard

2 suggestions

Open yangweijie opened this issue 10 years ago • 3 comments

I had use this plugin. It's amazing! But 3 bugs:

  • When the content is longer , the popup can't fit it's proper width and length. Some like this bellow: image
  • I want out an a in the html to let user jump to the php.net official site.But it didn't work.
  • When i return a string to use popup to show. It be cutted down. because the string contains '&$count'.It Seems to be a keyword. image
php "/Users/jay/Library/Application Support/Sublime Text 3/Packages/PhpNinJaManual/index.php" "Doc/find/function/str_replace/lang/zh"
<span class="keyword">mixed</span> <span class="entity name class">str_replace</span> (<span class="comment line">[ mixed <span class="string quoted">$search</span> ]' required  $search[ ,mixed <span class="string quoted">$replace</span> ]' required  $replace[ ,mixed <span class="string quoted">$subject</span> ]' required  $subject[ ,int <span class="string quoted">&$count</span> ]' optional  &$count</span>)
<p>该函数返回一个字符串或者数组。该字符串或数组是将 `subject` 中全部的 `search` 都被 `replace` 替换之后的结果。<br><br>如果没有一些特殊的替换需求(比如正则表达式),你应该使用该函数替换 ereg_replace() 和 preg_replace()。.</p>
<p>参数:</p>
<p>
    - 查找的目标值,也就是 needle`。一个数组可以指定多个目标。 <br>- `search` 的替换值。一个数组可以被用来指定多重替换。 <br>- 执行替换的数组或者字符串。也就是 haystack`。<br><br>如果 `subject` 是一个数组,替换操作将遍历整个 `subject`,返回值也将是一个数组。 <br>- 如果被指定,它的值将被设置为替换发生的次数。 <br></p>
Parse Error: $count</span> ]' optional  &$count</span>)
<p>该函数返回一个字符串或者数组。该字符串或数组是将 `subject` 中全部的 `search` 都被 `replace` 替换之后的结果。<br><br>如果没有一些特殊的替换需求(比如正则表达式),你应该使用该函数替换 ereg_replace() 和 preg_replace()。.</p>
<p>参数:</p>
<p>
    - 查找的目标值,也就是 needle`。一个数组可以指定多个目标。 <br>- `search` 的替换值。一个数组可以被用来指定多重替换。 <br>- 执行替换的数组或者字符串。也就是 haystack`。<br><br>如果 `subject` 是一个数组,替换操作将遍历整个 `subject`,返回值也将是一个数组。 <br>- 如果被指定,它的值将被设置为替换发生的次数。 <br></p></body></html> code: Unexpected character
Parse Error: </span> ]' optional  &$count</span>)
<p>该函数返回一个字符串或者数组。该字符串或数组是将 `subject` 中全部的 `search` 都被 `replace` 替换之后的结果。<br><br>如果没有一些特殊的替换需求(比如正则表达式),你应该使用该函数替换 ereg_replace() 和 preg_replace()。.</p>
<p>参数:</p>
<p>
    - 查找的目标值,也就是 needle`。一个数组可以指定多个目标。 <br>- `search` 的替换值。一个数组可以被用来指定多重替换。 <br>- 执行替换的数组或者字符串。也就是 haystack`。<br><br>如果 `subject` 是一个数组,替换操作将遍历整个 `subject`,返回值也将是一个数组。 <br>- 如果被指定,它的值将被设置为替换发生的次数。 <br></p></body></html> code: Unexpected character
Parse Error: /span> ]' optional  &$count</span>)
<p>该函数返回一个字符串或者数组。该字符串或数组是将 `subject` 中全部的 `search` 都被 `replace` 替换之后的结果。<br><br>如果没有一些特殊的替换需求(比如正则表达式),你应该使用该函数替换 ereg_replace() 和 preg_replace()。.</p>
<p>参数:</p>
<p>
    - 查找的目标值,也就是 needle`。一个数组可以指定多个目标。 <br>- `search` 的替换值。一个数组可以被用来指定多重替换。 <br>- 执行替换的数组或者字符串。也就是 haystack`。<br><br>如果 `subject` 是一个数组,替换操作将遍历整个 `subject`,返回值也将是一个数组。 <br>- 如果被指定,它的值将被设置为替换发生的次数。 <br></p></body></html> code: Unexpected character
Parse Error: > ]' optional  &$count</span>)
<p>该函数返回一个字符串或者数组。该字符串或数组是将 `subject` 中全部的 `search` 都被 `replace` 替换之后的结果。<br><br>如果没有一些特殊的替换需求(比如正则表达式),你应该使用该函数替换 ereg_replace() 和 preg_replace()。.</p>
<p>参数:</p>
<p>
    - 查找的目标值,也就是 needle`。一个数组可以指定多个目标。 <br>- `search` 的替换值。一个数组可以被用来指定多重替换。 <br>- 执行替换的数组或者字符串。也就是 haystack`。<br><br>如果 `subject` 是一个数组,替换操作将遍历整个 `subject`,返回值也将是一个数组。 <br>- 如果被指定,它的值将被设置为替换发生的次数。 <br></p></body></html> code: Unexpected character
Parse Error: $count</span>  code: Unknown entity
Parse Error: $count</span>)
<p>该函数返回一个字符串或者数组。该字符串或数组是将 `subject` 中全部的 `search` 都被 `replace` 替换之后的结果。<br><br>如果没有一些特殊的替换需求(比如正则表达式),你应该使用该函数替换 ereg_replace() 和 preg_replace()。.</p>
<p>参数:</p>
<p>
    - 查找的目标值,也就是 needle`。一个数组可以指定多个目标。 <br>- `search` 的替换值。一个数组可以被用来指定多重替换。 <br>- 执行替换的数组或者字符串。也就是 haystack`。<br><br>如果 `subject` 是一个数组,替换操作将遍历整个 `subject`,返回值也将是一个数组。 <br>- 如果被指定,它的值将被设置为替换发生的次数。 <br></p></body></html> code: Unexpected character
Parse Error: </span>)
<p>该函数返回一个字符串或者数组。该字符串或数组是将 `subject` 中全部的 `search` 都被 `replace` 替换之后的结果。<br><br>如果没有一些特殊的替换需求(比如正则表达式),你应该使用该函数替换 ereg_replace() 和 preg_replace()。.</p>
<p>参数:</p>
<p>
    - 查找的目标值,也就是 needle`。一个数组可以指定多个目标。 <br>- `search` 的替换值。一个数组可以被用来指定多重替换。 <br>- 执行替换的数组或者字符串。也就是 haystack`。<br><br>如果 `subject` 是一个数组,替换操作将遍历整个 `subject`,返回值也将是一个数组。 <br>- 如果被指定,它的值将被设置为替换发生的次数。 <br></p></body></html> code: Unexpected character
Parse Error: /span>)
<p>该函数返回一个字符串或者数组。该字符串或数组是将 `subject` 中全部的 `search` 都被 `replace` 替换之后的结果。<br><br>如果没有一些特殊的替换需求(比如正则表达式),你应该使用该函数替换 ereg_replace() 和 preg_replace()。.</p>
<p>参数:</p>
<p>
    - 查找的目标值,也就是 needle`。一个数组可以指定多个目标。 <br>- `search` 的替换值。一个数组可以被用来指定多重替换。 <br>- 执行替换的数组或者字符串。也就是 haystack`。<br><br>如果 `subject` 是一个数组,替换操作将遍历整个 `subject`,返回值也将是一个数组。 <br>- 如果被指定,它的值将被设置为替换发生的次数。 <br></p></body></html> code: Unexpected character
Parse Error: >)
<p>该函数返回一个字符串或者数组。该字符串或数组是将 `subject` 中全部的 `search` 都被 `replace` 替换之后的结果。<br><br>如果没有一些特殊的替换需求(比如正则表达式),你应该使用该函数替换 ereg_replace() 和 preg_replace()。.</p>
<p>参数:</p>
<p>
    - 查找的目标值,也就是 needle`。一个数组可以指定多个目标。 <br>- `search` 的替换值。一个数组可以被用来指定多重替换。 <br>- 执行替换的数组或者字符串。也就是 haystack`。<br><br>如果 `subject` 是一个数组,替换操作将遍历整个 `subject`,返回值也将是一个数组。 <br>- 如果被指定,它的值将被设置为替换发生的次数。 <br></p></body></html> code: Unexpected character
Parse Error: )
<p>该函数返回一个字符串或者数组。该字符串或数组是将 `subject` 中全部的 `search` 都被 `replace` 替换之后的结果。<br><br>如果没有一些特殊的替换需求(比如正则表达式),你应该使用该函数替换 ereg_replace() 和 preg_replace()。.</p>
<p>参数:</p>
<p>
    - 查找的目标值,也就是 needle`。一个数组可以指定多个目标。 <br>- `search` 的替换值。一个数组可以被用来指定多重替换。 <br>- 执行替换的数组或者字符串。也就是 haystack`。<br><br>如果 `subject` 是一个数组,替换操作将遍历整个 `subject`,返回值也将是一个数组。 <br>- 如果被指定,它的值将被设置为替换发生的次数。 <br></p></body></html> code: Unexpected character
Parse Error: $count</span>)
 code: Unknown entity

yangweijie avatar Sep 25 '15 06:09 yangweijie

There is a default maximum with of 300px which could be causing the width issue. You can adjust the maximum popup width by passing max_width as an argument to the function. I will have an example of this below. You can define a really high number like 1000, and if the line is shorter than 1000px then sublime should render a smaller popup automatically.

As for the url not opening the browser, I was able to do this with the following code:

class TooltipTestCommand(sublime_plugin.WindowCommand):
    def run(self):
        view = self.window.active_view()
        content = """<span class="storage type">array</span> <a class="entity name function" href="http://php.net/manual/en/function.explode.php">explode</a> ( string $delimiter , string $string [, int $limit ] )"""

        styled_popup.show_popup(view, content, on_navigate=self.nav, max_width=600)

    def nav(self, url):
        webbrowser.open(url)

View popups need to have a handler assigned for any links that get pressed. You tell the popup what function will handle any link actions by using the on_navigate argument. The value from the href attribute will get passed to that function where you can process it.

All of the default arguemnts for view.show_popup are still supported through the styled_popup.show_popup method, just pass the argument and value and it will just get passed to the view.show_popup method. This is something I should add to the README when I get a few minutes.

The last issue can be resolved by using &amp; instead of &. The html renderer mostly follows the same convention as web browsers when rendering html. Since there are some special characters in HTML that start with & (&copy;, &amp;, etc.) I believe sublime is trying to figure out what character should be rendered. Since &$count doesn't match any html entity sublime bails and does not finish rendering the rest of the string (this is my understanding based on testing).

screen shot 2015-09-25 at 10 34 55 am

Let me know if you run into any other issues or if you have any questions. I hope this helps!

huot25 avatar Sep 25 '15 14:09 huot25

Thanks for your Reply.They workd. And i also want know the hight param. I viewed the official api manual . I didn't find introduction for show_popup method of view. How dose u get to know it . Is there other api that the offical author didn't tell us. Once i thought Sublime 's UI api is week. So I have to show the doc by show_popup_menu method, and for 2 version, a bottom view. st3

st2

yangweijie avatar Sep 26 '15 10:09 yangweijie

Hi Jay,

Here is a snapshot of the shop_popup method.

screen shot 2015-09-26 at 8 59 37 am

I agree that the documentation is weak. The unofficial documentation is usually a good source for undocumented api methods, but unfortunately I could not find the popup methods on the site.

One thing I do when the sublime forum is down or I cannot find the documentation is go directly to the sublime.py or sublime_plugin.py files. You can find them in the contents of the SublimeText.app in applications on mac (show contents) and navigate to the files as I have done in the following snapshot. screen shot 2015-09-26 at 9 03 20 am

If you are on windows, I believe these files are in the programs install folder if installed or in the root of the zipped version. I don't have experience on a linux machine as most of my linux installs are headless servers which are accessed via ssh.

I will usually look through these files to see if any new methods are added to the various objects like window and view.

There is a flag COOPERATE_WITH_AUTO_COMPLETE which when passed as part of the flag argument will allow the popup to display correctly with any auto_complete lists that appear.

I hope this helps!

huot25 avatar Sep 26 '15 13:09 huot25