Select media query and contents in Sublime Text - sublimetext3

Is there a way to select every media query and its contents using Sublime Text 3? For example I have a CSS file with lots of #media print queries, I'd like to select all of them AND the contents in one go.
#media print {
.app-contact-panel__heading,
.app-prose-scope h3 {
font-size: 18pt;
line-height: 1.15;
}
}
I know I can select one #media print and press CMD + D to select the next one. Or CTRL + CMD + D to select all #media print in the doc, but neither selects the properties as well?
Can anyone help?

One way to do this would be via a plugin. The following plugin highlights all the contents of those media queries that begin with #media print {
import sublime
import sublime_plugin
class HighlightMediaQueryCommand(sublime_plugin.TextCommand):
def run(self, edit):
# This finds all the regions that are #media print {
media_regions = self.view.find_all(r"#media print {")
# This will clear the current Selection object.
self.view.sel().clear()
# We now add the region corresponding to the opening bracket of each media print query.
for regions in media_regions:
self.view.sel().add(sublime.Region(regions.end(), regions.end()))
# Next, we move the selection to the end of the brackets.
self.view.run_command("move_to", { "to": "brackets" })
# Now that we have access to the closing bracket of each media print query, we can construct the Region object for all media print queries with their contents also.
for i, sel in enumerate(self.view.sel()):
self.view.sel().add(sublime.Region(media_regions[i].begin(), sel.end() + 1))
def is_enabled(self):
# Enable the command to work only in a CSS file.
return self.view.settings().get("syntax") == "Packages/CSS/CSS.sublime-syntax"
In order to use this plugin, you'll have to save this code in a .py file in the User directory (go to Preferences -> Browse Packages ... via the top menu). Once saved, you can use this plugin in either of the following ways :-
The quickest & easiest way is to just type view.run_command("highlight_media_query") in the sublime console input and pressing enter while you are in the desired css file (press ctrl/cmd + ` to access the console).
If you do this very often, you can bind it to a keyboard shortcut. To do that, you would have to create a .sublime-keymap file in the User directory (the keymap file name doesn't matter, though as a convention it's generally kept Default (os).sublime-keymap where os = Windows, Linux or OSX based on your OS). Then paste in the following (the key binding is of your choice, it can be anything as long as it doesn't conflict with existing ones):-
[
{ "keys": ["ctrl+alt+m"], "command": "highlight_media_query" }
]
Doing that & pressing the said key binding (you need to have opened the said css file), should now select all #media print queries.

Related

A problem for selecting a image from the imagepupop dialog

One more question. If I create a image-popup dialog, I find it only works when the frontimage (the top one in the image list). If other image is selected, the program will report "the image used in the expression does not exist". I can not understand the logic behind this error.
The following is a modified code pasted in the answer of the previous question. It can work well if the first image is selected, but the error message appears if the second image is selected.
I use GSM 2.30.xxxx
Class CMyDLG : UIframe
{
TagGroup DLG,DLGItems,imgPop
object Init(object self)
{
DLG = DLGCreateDialog("Test",DLGItems)
imgPop = DLGCreateImagePopup()
DLGItems.DLGAddElement( imgPop )
return self.super.init(DLG)
}
image GetSelectedImage( object self )
{
string selectedImageLabel
imgPop.DLGGetValue(selectedImageLabel) //DLGGetValue can return the label of the image diretly
Result("\n" + selectedImageLabel)
// From the string, get the label
//string label = selectedImageLabel.left( selectedImageLabel.find(":") )
//Result("\n" + label)
// From label, return image
//return FindImageByLabel(label)
return FindImageByLabel(selectedImageLabel)
}
}
// main
{
object dlg = Alloc(CMyDLG).Init()
dlg.Pose()
image selected = dlg.GetSelectedImage()
if ( selected.ImageIsValid() )
{
selected.SetName( "Selected" + random())
selected.ShowImage()
}
else Throw( "Error, nothing selected." )
}
Using the test code on GMS 3.3 it works except for the bug mentioned. I presume it's the same for GMS 2.3 but I haven't verified.
To make sure we test the same thing, here are exact instructions and a break-down:
Start out with two images A and B and A being front-most.
Run script
Don't change anything in the dialog
Press OK
ERROR
The dialog - taggroup does not (yet) hold any value. It possibly should, I consider this a bug.
Start out with two images A and B and A being front-most.
Run script
Click the selection box and select "A" from the drop-down
Press OK
A is correctly selected
Start out with two images A and B and A being front-most.
Run script
Click the selection box and select "B" from the drop-down
Press OK
ERROR
The dialog - taggroup does not (yet) hold any value. It definitly should, I consider this a bug. It is most likely what you were describing?
Start out with two images A and B and A being front-most.
Run script
Click the selection box and select "A" from the drop-down
Click the selection box and select "B" from the drop-down
Press OK
B is correctly selected
To summarize:
Yes, there is a bug and nothing wrong with your script.
The selection box only works after selecting an items for the second time.
The example code (first script) in this answer seems to work on any of the open images when selected.
However, there is the (mentioned) bug that it does not work on first selection, only when you select one image and then another.
If your code fails, please provided a slimmed-down code-example of the failing code so that a mistake can possibly be spotted.

Sublime Text 3 / Emmet – Select both opening & closing tag (via Shortcut)

Just a quick question in order to optimize my workflow / productivity with Sublime Text 3 & Emmet...
So far I am able to (on Mac)
select the opening and closing tag via CMD + Shift + K
select the nested HTML / text of a wrapping attribute via CMD + Shift + A
But what I haven't found out yet is a way to select the opening and closing tag completely (with all possible values) in order to delete the surrounding tags.
To illustrate...
<span style="color: #660066;"><strong>Lorem ipsum dolor sit amed</strong></span>
Running CMD + Shift + K renders this selection:
...which doesn't allow me to instantly delete the code.
Any ideas / hints / workarounds you can think of? I researched both the web and the Sublime Text docs but to no avail...
Thanks & regards!
Highlight the tag you want to remove the opening and closing tags for and try CTRL + SHIFT + ;
That should delete the selected tag and it's closing partner.
The emmet documentation has this as the remove tag shortcut, but states the shortcut is CTRL + SHIFT + K, when infact (on my setup at least), it's CTRL + SHIFT + ; in Sublime Text 3.
If this doesn't work, you should be able to find what the default key binding is by checking your default key bindings file under Preferences > Package Settings > Emmet > Key Bindings - Default. Run a search in this file for "remove_tag" and see what binding is attached to it.
If for some reason it doesn't exist or you'd like to change the binding, you can do so by editing your user key bindings file under Preferences > Package Settings > Emmet > Key Bindings - User.
Simply add:
[
{
"keys": [
"shift+ctrl+;"
],
"args": {
"action": "remove_tag"
},
"command": "run_emmet_action",
"context": [
{
"key": "emmet_action_enabled.remove_tag"
}
]
}
]

Python Selenium, the text of the next element

I can get the text of the first element. But I do not know how to go through the entire list and get the text of each element. Here is the tree from the site:
Screenshot
So I get the text of the first element:
driver.find_element_by_xpath("//a[#my-peer-link='participant.user_id']").click()
print(driver.find_element_by_xpath("//span[#ng-bind=\"'#' + user.username\"]").text)
In each
div class="md_modal_list_peer_wrap clearfix" ng-repeat="participant in
chatFull.participants.participants"
is contained
div class="md_modal_list_peer_name"
which contains
a class="md_modal_list_peer_name"
my-peer-link="participant.user_id">Олег
which you need to press. That is, execute:
driver.find_element_by_xpath("//a[#my-peer-link='participant.user_id']").click()
After that, a new window opens, from which I get the text of the element:
driver.find_element_by_xpath("//span[#ng-bind=\"'#' + user.username\"]").text
But there are several of these elements and I need to get the text with everyone:
div class="md_modal_list_peer_wrap clearfix" ng-repeat="participant in
chatFull.participants.participants"
How to do it?
Vladimir, I haven't done a careful analysis of this problem; however, could it be as simple as this?
Rather than using
driver.find_element_by_xpath("//span[#ng-bind=\"'#' + user.username\"]").text
could you use:
for span in driver.find_elements_by_xpath("//span[#ng-bind=\"'#' + user.username\"]"):
span.text
(Notice plural in `find_elements_by_xpath'.)
You'll need to click each element and store the text in a list:
So first use
elements_to_click = driver.find_elements_by_xpath("//a[#my-peer-link='participant.user_id']"
This will return a list of elements
Loop through those elements by
clicking on element
switch to the new window (When a new WindowHandle was created, otherwise skip this step.)
get the text via
driver.find_element_by_xpath("//span[#ng-bind=\"'#' + user.username\"]").text
store it in a list
close window (When a new WindowHandle is created, otherwise skip this step.)
switch to previous window

How to verify whether a blinking cursor is currently inside of a text box through TestComplete

I am trying to verify that the text box gets the focus (the blinking cursor gets placed inside of it) after a certain action. I tried to use the Focused property, but it does not seem to work, or the object doesnt have this property. This is on a Web application. Here is the code
reportPage = Aliases.iexplore.IESA;
saveWindow = reportPage.Find("ObjectIdentifier", "MainContent_saveFilterSetDialog_saveDialog", 50, true);
saveWindowNameTextBox = saveWindow.Find("ObjectIdentifier", "*MainContent_*_sfsName", 25, true);
if(saveWindowNameTextBox.Focused == true)
Log.Message("The blinking cursor is inside of the name text box")
else
Log.Error("The blinking cursor is not inside of the name text box")
The logging window says "Waiting for Focused", then it fails and the log says "Unable to find the object with the specified properties"
NOTE: When I inspect this text box object in the object inspector window, "Focused" is not listed in the list of properties.
Is there another way to accomplish this?
I was able to accomplish this using an HTML DOM property activeElement
var actualFocusedElement = Sys.Browser().Page("*BC/Report*").contentDocument.activeElement.id
if(aqString.Contains(actualElement, "saveDialog_tmpl_sfsName", 0, true))
Log.Message("The blinking cursor is inside of the name text box")
else
Log.Error("The blinking cursor is not inside of the name text box")

Quickest way to select an entire Sass ruleset in Vim?

Just starting with Vim and I wondered – given a Sass block like this:
.thing {
width: 100%;
color: $color1;
.nested {
height: 1rem;
}
}
If my cursor is at the 'd' within 'width', what's the quickest way to visually select the entire rule set, selector, braces and all?
At present I am using 'Shift+}' to jump to the next blank line and then 'v' for visual and 'Shift+{' to select the prior block. Any better way?
You're close. As you're already using the { and } motions to the borders of the current paragraph, just use the related text object: Vip, where V starts (linewise, but you can also use v as this text object forces this) visual mode, and ip selects the inner paragraph.

Resources